﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using cfg = System.Configuration;
using GoldPrinter;
using WeifenLuo.WinFormsUI.Docking;

namespace BYManageInfoSystem
{
    public partial class Frm_CommerCheckFillBoxSheet : DockContent
    {
        private DGBY.BLL.BYBackQingDanTab m_bllBYBackQingDanTab = new DGBY.BLL.BYBackQingDanTab();

        private DGBY.BLL.HxdNoTab m_bllHxdNoTab = new DGBY.BLL.HxdNoTab();
        private DGBY.BLL.FeeHKYSTruePayTab m_bllFeeHKYSTruePayTab = new DGBY.BLL.FeeHKYSTruePayTab();
        private DGBY.BLL.FeeDZTruePayTab m_bllFeeDZTruePayTab = new DGBY.BLL.FeeDZTruePayTab();

        private DGBY.BLL.FeeHKCWTruePayTab m_bllFeeHKCWTruePayTab = new DGBY.BLL.FeeHKCWTruePayTab();
        private DGBY.BLL.FeeBGTruePayTab m_bllFeeBGTruePayTab = new DGBY.BLL.FeeBGTruePayTab();
        private DGBY.BLL.FeeDLCWTruePayTab m_bllFeeDLCWTruePayTab = new DGBY.BLL.FeeDLCWTruePayTab();
        private DGBY.BLL.FeeDHLTruePayTab m_bllFeeDHLTruePayTab = new DGBY.BLL.FeeDHLTruePayTab();
        //private DGBY.BLL.FeeZXZTruePayTab m_bllFeeZXZTruePayTab = new DGBY.BLL.FeeZXZTruePayTab();
        //private DGBY.BLL.FeeJCFTruePayTab m_bllFeeJCFTruePayTab = new DGBY.BLL.FeeJCFTruePayTab();

        private DGBY.BLL.FeeSJTruePayTab m_bllFeeSJTruePayTab = new DGBY.BLL.FeeSJTruePayTab();

        private DGBY.BLL.LogRecTab m_bllLogRecTab = new DGBY.BLL.LogRecTab();
        private DGBY.BLL.FacFeeTabNew m_bllFacFeeTabNew = new DGBY.BLL.FacFeeTabNew();
        private DGBY.BLL.FacFeeRelationTab m_bllFacFeeRelationTab = new DGBY.BLL.FacFeeRelationTab();
       // private DGBY.BLL.FacFeeTab m_bllFacFeeTab = new DGBY.BLL.FacFeeTab();
        private DGBY.BLL.FeeTab m_bllFeeTab = new DGBY.BLL.FeeTab();

        private int m_nDelIndex = -1;
        private bool m_bInsertFlag = false;
        private DGBY.BLL.FinCheckInvoiceRecordDetailTab_New m_bllFinCheckInvoiceRecordDetailTab_New = new DGBY.BLL.FinCheckInvoiceRecordDetailTab_New();
        private DGBY.BLL.FinInvoiceRecordTab_New m_bllFinInvoiceRecordTab_New = new DGBY.BLL.FinInvoiceRecordTab_New();
        private DGBY.BLL.TYInvoiceTab m_bllTYInvoiceTab = new DGBY.BLL.TYInvoiceTab();
       // private DGBY.BLL.BGDComeBackTab m_bllBGDComeBackTab = new DGBY.BLL.BGDComeBackTab();
        private DGBY.BLL.BGCKHTTab m_bllBGCKHTTab = new DGBY.BLL.BGCKHTTab();
        private DGBY.BLL.SJGouHHTTab m_bllSJGouHHTTab = new DGBY.BLL.SJGouHHTTab();
        private DGBY.BLL.SJCKHTTab m_bllSJCKHTTab = new DGBY.BLL.SJCKHTTab();
        private DGBY.BLL.SJPackGoodsMXTab m_bllSJPackGoodsMXTab = new DGBY.BLL.SJPackGoodsMXTab();
        private DGBY.BLL.SJPackingTab m_bllSJPackingTab = new DGBY.BLL.SJPackingTab();
        private DGBY.BLL.BYCompanyTab m_bllBYCompanyTab = new DGBY.BLL.BYCompanyTab();
        private DGBY.BLL.PaidanRegisterTab m_bllPaidanRegisterTab = new DGBY.BLL.PaidanRegisterTab();
        private DGBY.BLL.SHCompTab m_bllSHCompTab = new DGBY.BLL.SHCompTab();
        private DGBY.BLL.ZYHarborTab m_bllZYHarborTab = new DGBY.BLL.ZYHarborTab();
        private DGBY.BLL.QYCountryTab m_bllQYCountryTab = new DGBY.BLL.QYCountryTab();
        private DGBY.BLL.BZSortTab m_bllBZSortTab = new DGBY.BLL.BZSortTab();

        private DGBY.BLL.NumDanWeiTab m_bllNumDanWeiTab = new DGBY.BLL.NumDanWeiTab();
        private DGBY.BLL.BiZhiTab m_bllBiZhiTab = new DGBY.BLL.BiZhiTab();
        private DGBY.BLL.BGPackingTab m_bllBGPackingTab = new DGBY.BLL.BGPackingTab();
        private DGBY.BLL.BGPackGoodsMXTab m_bllBGPackGoodsMXTab = new DGBY.BLL.BGPackGoodsMXTab();

        private DGBY.BLL.FactoryGoodsTab m_bllFactoryGoodsTab = new DGBY.BLL.FactoryGoodsTab();
        private DGBY.BLL.FactoryDataTab m_bllFactoryDataTab = new DGBY.BLL.FactoryDataTab();
        private DGBY.BLL.SJHuiLvTab m_bllSJHuiLvTab = new DGBY.BLL.SJHuiLvTab();

        private DataSet m_dsPaidan = new DataSet();
       // private DataSet m_dsUltraGrid2 = new DataSet();
        private int m_nSelectSJPackingTabID = 0;

        private bool m_bFlag = false;
        protected string templetFilePath = cfg.ConfigurationSettings.AppSettings["TempletFilePath"];
        //ExcelBase eB = new ExcelBase();
        private int m_nSelectSJPackGoodsMXTabID = 0;
        Hashtable m_SQLStringList = new Hashtable();
        ArrayList m_arrayList = new ArrayList();
      //  public static int m_nPaidanRegisterTabID = 0;

        //public static event EventHandler<CommerCheckFillBoxEventArgs> onAdd;

        //public void OnAdd(CommerCheckFillBoxEventArgs addEventArgs)
        //{
        //    if (onAdd != null)
        //        onAdd(this, addEventArgs);
        //}

        public Frm_CommerCheckFillBoxSheet()
        {
            InitializeComponent();
        }

        //public Frm_CommerCheckFillBoxSheet()
        //{
        //    InitializeComponent();
        //    //m_nPaidanRegisterTabID = nID;
        //}

        private void InitCombox()
        {
            m_dsPaidan = m_bllPaidanRegisterTab.GetNameAndID("");
            if (m_dsPaidan.Tables.Count > 0 && m_dsPaidan.Tables[0].Rows.Count > 0)
            {
                this.comboBoxContractNo.DataSource = m_dsPaidan.Tables[0];
                this.comboBoxContractNo.ValueMember = "PaidanRegisterTabID";
                this.comboBoxContractNo.DisplayMember = "合同编号";
                this.comboBoxContractNo.AutoCompleteSource = AutoCompleteSource.ListItems;
                this.comboBoxContractNo.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                //if (m_nPaidanRegisterTabID != 0)
                this.comboBoxContractNo.SelectedValue = Frm_Main.m_nContractSelectValue;
                //else
                   // this.comboBoxContractNo.SelectedIndex = Frm_Main.m_nContractSelectIndex;
            }

            DataSet ds = m_bllSHCompTab.GetList("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxRecvGoodsComp.DataSource = ds.Tables[0];
                this.comboBoxRecvGoodsComp.DisplayMember = "公司名字";
                this.comboBoxRecvGoodsComp.ValueMember = "SHCompTabID";
                this.comboBoxRecvGoodsComp.SelectedIndex = 0;
            }

            ds = m_bllQYCountryTab.GetList("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxStartCountry.DataSource = ds.Tables[0];
                this.comboBoxStartCountry.DisplayMember = "起运国";
                this.comboBoxStartCountry.ValueMember = "QYCountryTabID";
                this.comboBoxStartCountry.SelectedIndex = 0;
            }

            ds = m_bllZYHarborTab.GetList("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxPort.DataSource = ds.Tables[0];
                this.comboBoxPort.DisplayMember = "装运港名称";
                this.comboBoxPort.ValueMember = "ZYHarborTabID";
                this.comboBoxPort.SelectedIndex = 0;
            }

            ds = m_bllBZSortTab.GetList("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxOutSideCate.DataSource = ds.Tables[0];
                this.comboBoxOutSideCate.DisplayMember = "包装种类";
                this.comboBoxOutSideCate.ValueMember = "BZSortTabID";
                this.comboBoxOutSideCate.SelectedIndex = 0;
            }
            ds = m_bllBiZhiTab.GetList("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxCoinUnit2.DataSource = ds.Tables[0];
                this.comboBoxCoinUnit2.DisplayMember = "币制名称";
                this.comboBoxCoinUnit2.ValueMember = "BiZhiTabID";
                this.comboBoxCoinUnit2.SelectedIndex = 0;
            }




        }


        private bool CheckSBDate()
        {
            bool bRet = false;
            if (!Frm_Main.m_bCompleteVer)
            {
                DataSet dsHxdNoTab = m_bllHxdNoTab.GetList("HxdNoTab.PaidanRegisterTabID = '" + this.comboBoxContractNo.SelectedValue + "'");
                if (dsHxdNoTab.Tables.Count > 0 && dsHxdNoTab.Tables[0].Rows.Count > 0)
                {
                    int nHxdNoTabID = Convert.ToInt32(dsHxdNoTab.Tables[0].Rows[0]["HxdNoTabID"].ToString(), 10);
                    DGBY.Model.HxdNoTab modelHxdNoTabOld = m_bllHxdNoTab.GetModel(nHxdNoTabID);
                    int nYear = modelHxdNoTabOld.SBDate.Value.Date.Year;
                    if (nYear != 1900)
                    {
                        bRet = true;
                    }
                }

            }

            return bRet;
        }
        private void Frm_CommerCheckFillBoxSheet_Load(object sender, EventArgs e)
        {
            ClassUltraGridCommonSet.LocalPrintPreveiw();
            InitCombox();
        }

        private void ShowFillBoxSheetByContractCode(string strContractCode)
        {
            DataSet m_ds = m_bllSJPackingTab.ShowOneSJPackRec("ContractCode = '" + strContractCode + "'");


            ultraGrid1.DataSource = null;
          
            if (m_ds.Tables.Count > 0 && m_ds.Tables[0].Rows.Count > 0)
            {
                ultraGrid1.DataSource = m_ds.Tables[0];
                ultraGrid1.DisplayLayout.Bands[0].Columns[0].Hidden = true;
                ShowAllMXRecordInDataGridView(Convert.ToInt32(m_ds.Tables[0].Rows[0]["SJPackingTabID"].ToString(), 10));
                m_nSelectSJPackingTabID = Convert.ToInt32(m_ds.Tables[0].Rows[0]["SJPackingTabID"].ToString());
                cellSJPackingTabClick();
                this.textBoxFirstSheetNo.Text = m_ds.Tables[0].Rows[0]["单据编号"].ToString();
                this.ultraGrid2.Text = "商检装箱单明细(单据编号：" + this.textBoxFirstSheetNo.Text + ")";
            }
            else
            {
                DataSet ds = m_bllBYBackQingDanTab.GetBackQingInfo("ContractCode = '" + strContractCode + "'");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    string strTemp = ds.Tables[0].Rows[0]["出口方式"].ToString();
                    if (strTemp == "东莞转关入深圳仓" || strTemp == "东莞整柜转关深圳还柜")
                    {
                        this.comboBoxPort.SelectedValue = 2;
                    }
              
                }
                
                
                ultraGrid2.DataSource = null;
                m_nSelectSJPackingTabID = 0;
                this.textBoxFirstSheetNo.Text = "";
            }
            
        }

        private void SyncContractNo()
        {
            try
            {

               // string str = this.comboBoxContractNo.SelectedValue.ToString();

                int nID = Frm_Main.m_nContractSelectValue;

                DataSet ds = m_bllPaidanRegisterTab.GetList("PaidanRegisterTabID = '" + nID + "'");
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    //int nCompId = Convert.ToInt32(ds.Tables[0].Rows[0]["BYCompanyTabID"].ToString(), 10);
                    //DataSet ds1 = m_bllBYCompanyTab.GetList("BYCompanyTabID = '" + nCompId + "'");
                    //if (ds1.Tables.Count > 0 && ds1.Tables[0].Rows.Count > 0)
                    //{
                    //    this.textBoxCompany.Text = ds1.Tables[0].Rows[0]["经营单位名称"].ToString();
                    //}
                    string strContractCode = ds.Tables[0].Rows[0]["ContractCode"].ToString();
                    ShowFillBoxSheetByContractCode(strContractCode);
                }

          

                //this.textBoxMark.Text = "";
                //this.textBoxNote.Text = "";


            }
            catch (Exception ex)
            {
                string str = ex.Message;
            }
        }

        private void comboBoxContractNo_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                
                string str = this.comboBoxContractNo.SelectedValue.ToString();

                int nID = Convert.ToInt32(str, 10);
                //m_nPaidanRegisterTabID = nID;
                DataSet ds = m_bllPaidanRegisterTab.GetList("PaidanRegisterTabID = '" + nID + "'");
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    int nCompId = Convert.ToInt32(ds.Tables[0].Rows[0]["BYCompanyTabID"].ToString(), 10);
                    DataSet ds1 = m_bllBYCompanyTab.GetList("BYCompanyTabID = '" + nCompId + "'");
                    if (ds1.Tables.Count > 0 && ds1.Tables[0].Rows.Count > 0)
                    {
                        this.textBoxCompany.Text = ds1.Tables[0].Rows[0]["经营单位名称"].ToString();
                    }
                }
                
                string strContractCode = ds.Tables[0].Rows[0]["ContractCode"].ToString();
                ShowFillBoxSheetByContractCode(strContractCode);

                this.textBoxMark.Text = "";
                this.textBoxNote.Text = "";


            }
            catch (Exception ex) 
            {
                string str = ex.Message;
            }
        }

        private void ShowAllRecordInDataGridView(string strWhere)
        {

            DataSet m_ds = m_bllSJPackingTab.ShowOneSJPackRec(strWhere);
            ultraGrid1.DataSource = null;

            if (m_ds.Tables.Count > 0 && m_ds.Tables[0].Rows.Count > 0)
            {
                ultraGrid1.DataSource = m_ds.Tables[0];
                ultraGrid1.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            }
        }

        private void buttonShowAll_Click(object sender, EventArgs e)
        {
            m_dsPaidan = m_bllPaidanRegisterTab.GetNameAndIDAll("");
            if (m_dsPaidan.Tables.Count > 0 && m_dsPaidan.Tables[0].Rows.Count > 0)
            {
                this.comboBoxContractNo.DataSource = m_dsPaidan.Tables[0];
                this.comboBoxContractNo.ValueMember = "PaidanRegisterTabID";
                this.comboBoxContractNo.DisplayMember = "合同编号";
                this.comboBoxContractNo.AutoCompleteSource = AutoCompleteSource.ListItems;
                this.comboBoxContractNo.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                //if (m_nPaidanRegisterTabID != 0)
                this.comboBoxContractNo.SelectedValue = Frm_Main.m_nContractSelectValue;
                //else
                // this.comboBoxContractNo.SelectedIndex = Frm_Main.m_nContractSelectIndex;
            }
            ShowAllRecordInDataGridView("");
            this.ultraGrid1.Dock = DockStyle.Fill;
            this.groupBoxGoodsDetail.Visible = false;
        }

        //private void dataGridViewFillBoxSheetList_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        //{
        //    string strSJPackingTabID = this.dataGridViewFillBoxSheetList.Rows[this.dataGridViewFillBoxSheetList.CurrentCell.RowIndex].Cells[0].Value.ToString();
        //    m_nSelectSJPackingTabID = Convert.ToInt32(strSJPackingTabID, 10);
        //    cellSJPackingTabClick();
        //}

        private void cellSJPackingTabClick()
        {
            this.ultraGrid1.Dock = DockStyle.None;
            this.groupBoxGoodsDetail.Visible = true;
            DGBY.Model.SJPackingTab modelSJPackingTab = m_bllSJPackingTab.GetModel(m_nSelectSJPackingTabID);
            if (modelSJPackingTab != null)
            {
                this.textBoxNote.Text = modelSJPackingTab.Note;
                this.textBoxFirstSheetNo.Text = modelSJPackingTab.SJPackDJNo.ToString();
                this.textBoxMark.Text = modelSJPackingTab.ShoeBrand;
                this.textBoxMaiTou.Text = modelSJPackingTab.ShipMarks;
                //this.textBoxContractNo.Text = modelSJPackingTab.ContractCode;
                if (modelSJPackingTab.BiZhiTabID != null)
                    this.comboBoxCoinUnit2.SelectedValue = modelSJPackingTab.BiZhiTabID;
                if (modelSJPackingTab.SHCompTabID != null)
                    this.comboBoxRecvGoodsComp.SelectedValue = modelSJPackingTab.SHCompTabID;
                if (modelSJPackingTab.QYCountryTabID != null)
                    this.comboBoxStartCountry.SelectedValue = modelSJPackingTab.QYCountryTabID;
                if (modelSJPackingTab.ZYHarborTabID != null)
                    this.comboBoxPort.SelectedValue = modelSJPackingTab.ZYHarborTabID;
                if (modelSJPackingTab.BZSortTabID != null)
                    this.comboBoxOutSideCate.SelectedValue = modelSJPackingTab.BZSortTabID;
                if (modelSJPackingTab.PaidanRegisterTabID != null)
                    this.comboBoxContractNo.SelectedValue = modelSJPackingTab.PaidanRegisterTabID;

                if (modelSJPackingTab.IsShoePack == "否")
                {
                    this.checkBoxIsShoe.Checked = false;
                    this.textBoxMark.ReadOnly = true;
                }
                else
                {
                    this.checkBoxIsShoe.Checked = true;
                    this.textBoxMark.ReadOnly = false;
                }
                ShowAllMXRecordInDataGridView(m_nSelectSJPackingTabID);
            }
            else
            {
                this.textBoxNote.Text = "";
                this.textBoxSecondSheetNo.Text = "";
                this.textBoxMark.Text = "";
                this.textBoxMaiTou.Text = "";
            }
        }

        private Int64 MakeSJPackDJNo()
        {
            string strDate = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString().PadLeft(2, '0') + System.DateTime.Now.Day.ToString().PadLeft(2, '0');
            DataSet ds = m_bllSJPackingTab.GetSJPackDJNoByDate("SJPackDJDate = '" + strDate + "'");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                string strDJNo = ds.Tables[0].Rows[0]["MaxJPackDJNum"].ToString();
                long nDJNo = 0;
                if (strDJNo != "")
                    nDJNo = Convert.ToInt64(strDJNo, 10);
                nDJNo++;
                string strTemp = "";
                if (strDJNo != "")
                    strTemp = string.Format("{0:d4}", nDJNo);
                else
                    strTemp = strDate + string.Format("{0:d4}", nDJNo);
                 
                return Convert.ToInt64(strTemp, 10);
            }

            return 0;
        }
        private Int64 MakeSJCKouDJNo()
        {
            string strDate = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString().PadLeft(2, '0') + System.DateTime.Now.Day.ToString().PadLeft(2, '0');
            DataSet ds = m_bllSJCKHTTab.GetSJPackDJNoByDate("SJCKHTDJDate = '" + strDate + "'");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                string strDJNo = ds.Tables[0].Rows[0]["MaxJPackDJNum"].ToString();
                long nDJNo = 0;
                if (strDJNo != "")
                    nDJNo = Convert.ToInt64(strDJNo, 10);
                nDJNo++;
                string strTemp = "";
                if (strDJNo != "")
                    strTemp = string.Format("{0:d4}", nDJNo);
                else
                    strTemp = strDate + string.Format("{0:d4}", nDJNo);

                return Convert.ToInt64(strTemp, 10);
            }

            return 0;
        }
        private Int64 MakeGHPackDJNo()
        {
            string strDate = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString().PadLeft(2, '0') + System.DateTime.Now.Day.ToString().PadLeft(2, '0');
            DataSet ds = m_bllSJGouHHTTab.GetSJGouHHTTabByDate("SJGouHHTDJDate = '" + strDate + "'");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                string strDJNo = ds.Tables[0].Rows[0]["MaxJPackDJNum"].ToString();
                long nDJNo = 0;
                if (strDJNo != "")
                    nDJNo = Convert.ToInt64(strDJNo, 10);
                nDJNo++;
                string strTemp = "";
                if (strDJNo != "")
                    strTemp = string.Format("{0:d4}", nDJNo);
                else
                    strTemp = strDate + string.Format("{0:d4}", nDJNo);

                return Convert.ToInt64(strTemp, 10);
            }

            return 0;
        }

        //增加回收报关单记录
        //private void AddOneBackBGDRec(int nPaidanRegisterTabID)
        //{
        //    try
        //    {
        //        DataSet ds = m_bllBGDComeBackTab.GetList("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

        //        if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
        //        {
        //            return;
        //        }
        //        //回收报关单
        //        DGBY.Model.BGDComeBackTab modelBGDComeBackTab = new DGBY.Model.BGDComeBackTab();

        //        modelBGDComeBackTab.BGDNo = "";
        //        modelBGDComeBackTab.FHDWName = "";
        //        modelBGDComeBackTab.PZWH = "";
        //        modelBGDComeBackTab.TotalPieceNum = "0";
        //        modelBGDComeBackTab.TotalMaoWeight = "0";
        //        modelBGDComeBackTab.TotalJingWeight = "0";
        //        modelBGDComeBackTab.SFDZName = "";
        //        modelBGDComeBackTab.SFDZNo = "";
        //        modelBGDComeBackTab.Note = "";
        //        modelBGDComeBackTab.KaiPiaoHuiLv = 0;

        //        modelBGDComeBackTab.SBDate = System.DateTime.Now.Date;
        //        modelBGDComeBackTab.CKouDate = System.DateTime.Now.Date;


        //        modelBGDComeBackTab.PaidanRegisterTabID = nPaidanRegisterTabID;
        //        modelBGDComeBackTab.YSMethodTabID = 1;
        //        modelBGDComeBackTab.MDCountryTabID = 1;
        //        modelBGDComeBackTab.JNHYPosTabID = 1;
        //        modelBGDComeBackTab.ChengJFSTabID = 1;
        //        modelBGDComeBackTab.MDPortTabID = 1;
        //        modelBGDComeBackTab.BZSortTabID = 1;
        //        modelBGDComeBackTab.BGHDataTabID = 1;
        //        modelBGDComeBackTab.HaiGuanTabID = 1;
        //        modelBGDComeBackTab.MaoYiFSTabID = 1;
        //        modelBGDComeBackTab.JieHuiFSTabID = 1;
        //        modelBGDComeBackTab.ZhengMXZTabID = 1;
        //        modelBGDComeBackTab.IsSyncComplete = 1;
        //        modelBGDComeBackTab.BiZhiTabID = 1;

        //        m_bllBGDComeBackTab.TransAdd(modelBGDComeBackTab, m_SQLStringList, m_arrayList);



        //    }
        //    catch (System.Exception ex)
        //    {
        //        MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

        //    }
        //}

        //增加报关出口合同记录
        private void AddOneBGCKContractRec(int nPaidanRegisterTabID, bool bIsDisCount, ref int nYSMethodTabID)
        {
            try
            {
                DataSet ds = m_bllBGCKHTTab.GetList("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    return;
                }
                DGBY.Model.BGCKHTTab modelBGCKHTTab = new DGBY.Model.BGCKHTTab();
                ds = m_bllPaidanRegisterTab.GetTransWay("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    modelBGCKHTTab.YSMethodTabID = (int)ds.Tables[0].Rows[0]["YSMethodTabID"];
                }
                modelBGCKHTTab.isDisCount = bIsDisCount;
                modelBGCKHTTab.JYCompDaiBiao = "";
                modelBGCKHTTab.SHCompDaiBiao = "";
                modelBGCKHTTab.DYZ = "";
                modelBGCKHTTab.BaoXian = "由买方负责投保。";
                modelBGCKHTTab.FKCondition = "卖方发货后120天内电汇付款。";
                modelBGCKHTTab.SPCheck = "由卖方申请，并保证按商检部门规定执行。";
                modelBGCKHTTab.ZYMethod = "由双方协商解决或交由签约地有管辖权法院裁决。";
                modelBGCKHTTab.SCPiNo = "";
                modelBGCKHTTab.QTThing = "由双方协商解决。";
                modelBGCKHTTab.Note = "";

                modelBGCKHTTab.BGCKHTDJNo = MakeBGContractDJNo();

                //modelBGCKHTTab.QDDate = this.dateTimePickerMakeProtocolDate.Value;
                //modelBGCKHTTab.JHDate = this.dateTimePickerDeadLine.Value;
                modelBGCKHTTab.QDDate = System.DateTime.Now.Date;
                modelBGCKHTTab.JHDate = System.DateTime.Now.Date;
                modelBGCKHTTab.BGCKHTDJDate = System.DateTime.Now.Date;

                modelBGCKHTTab.InvoiceNo = "";
                modelBGCKHTTab.InvoiceNote = "";

                modelBGCKHTTab.QDPlaceTabID = 1;

                //modelBGCKHTTab.YSMethodTabID = 1;

                modelBGCKHTTab.MDCountryTabID = 1;

                modelBGCKHTTab.JNHYPosTabID = 1;

                modelBGCKHTTab.PaidanRegisterTabID = nPaidanRegisterTabID;

                modelBGCKHTTab.ZYHarborTabID = 1;

                modelBGCKHTTab.SHCompTabID = 1;

                modelBGCKHTTab.BZSortTabID = 1;

                ds = m_bllBYBackQingDanTab.GetBackQingInfoByID("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    string strTemp = ds.Tables[0].Rows[0]["出口方式"].ToString();
                    if (strTemp == "只到香港不再出口")
                    {
                        modelBGCKHTTab.MDCountryTabID = 23;
                    }

                }

                m_bllBGCKHTTab.TransAdd(modelBGCKHTTab, m_SQLStringList, m_arrayList);

                nYSMethodTabID = modelBGCKHTTab.YSMethodTabID;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        }
        private void ModifySjGHContractRecHuilv(int nPaidanRegisterTabID)
        {
            try
            {
                DataSet ds = m_bllSJGouHHTTab.GetList("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    int nSJGouHHTTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["SJGouHHTTabID"].ToString(), 10);
                    DGBY.Model.SJGouHHTTab modelSJGouHHTTab = m_bllSJGouHHTTab.GetModel(nSJGouHHTTabID);
                    modelSJGouHHTTab.HuiLv = GetSelectHuiLvValue();
                    m_bllSJGouHHTTab.Update(modelSJGouHHTTab);
                }
                else
                {
                    return;
                }
               

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }
        //增加购货合同草稿记录
        private void AddOneSjGHContractRec(int nPaidanRegisterTabID)
        {
            try
            {
                DataSet ds = m_bllSJGouHHTTab.GetList("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    return;
                }
                DGBY.Model.SJGouHHTTab modelSJGouHHTTab = new DGBY.Model.SJGouHHTTab();

                modelSJGouHHTTab.JYCompDaiBiao = "";
                modelSJGouHHTTab.FacDaiBiao = "";

                modelSJGouHHTTab.JHFSPosYunCost = "";
                modelSJGouHHTTab.HKJSMethod = "发货后凭供方真实有效的17%增值税发票及出口货物专用缴款书付款";
                modelSJGouHHTTab.CPZhiLiang = @"供方应对产品质量负责，货物发运前，需经检验才能发运，发运后自交货日起10天内，经需方申请商检或用户检验的，如质量不符合封存样板，商检证书或产品说明书规定，由此产生的一切费用、损失由供方负责。";
                modelSJGouHHTTab.WYZeRen = @"供需双方必须遵守重合同守信用原则，严格执行本合同的条款，如任何一方违约，须向对方支付违约金合同总值10%.";
                modelSJGouHHTTab.JFJieJue = "以诉讼方式解决纠纷由广东省东莞人民法院管辖";
                modelSJGouHHTTab.QTThing = "";

                /********************************************************************/
                // 通过查询汇率表获取汇率 2012--8-21
                // modelSJGouHHTTab.HuiLv = 0; 

                modelSJGouHHTTab.HuiLv =  GetSelectHuiLvValue();
                /********************************************************************/

                modelSJGouHHTTab.Note = "";


                modelSJGouHHTTab.SJGouHHTDJNo = MakeGHPackDJNo();
                modelSJGouHHTTab.SJGouHHTDJDate = System.DateTime.Now.Date;

                modelSJGouHHTTab.PaidanRegisterTabID = nPaidanRegisterTabID;

                ds = m_bllPaidanRegisterTab.GetFacAddrByContract("PaidanRegisterTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    modelSJGouHHTTab.FacAddrTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["FacAddrTabID"].ToString(), 10); 
                }
    


                m_bllSJGouHHTTab.TransAdd(modelSJGouHHTTab, m_SQLStringList, m_arrayList);

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }

        private decimal GetSelectHuiLvValue()
        {
            decimal dHuiLv = 0;

            string strBiZhiTabID = this.comboBoxCoinUnit2.SelectedValue.ToString();
            DataSet ds = m_bllSJHuiLvTab.GetList("BiZhiTabID = '" + strBiZhiTabID + "'");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dHuiLv = Convert.ToDecimal(ds.Tables[0].Rows[0]["SJHuiLv"].ToString());
            }

            return dHuiLv;
        }

        //增加商检出口合同和发票记录
        private void AddOneSjCKContractRec(int nPaidanRegisterTabID, bool bIsDisCount)
        {
            DataSet ds = m_bllSJCKHTTab.GetList("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return;
            }

            DGBY.Model.SJCKHTTab modelSJCKHTTab = new DGBY.Model.SJCKHTTab();
            ds = m_bllPaidanRegisterTab.GetTransWay("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                modelSJCKHTTab.YSMethodTabID = (int)ds.Tables[0].Rows[0]["YSMethodTabID"];
            }

        

            modelSJCKHTTab.isDisCount = bIsDisCount;

            modelSJCKHTTab.SJCKHTDJNo = MakeSJCKouDJNo();

            modelSJCKHTTab.QDDate = System.DateTime.Now.Date;
            modelSJCKHTTab.JHDate = System.DateTime.Now.AddMonths(1).Date;
            //modelSJCKHTTabOld.JHDate = this.dateTimePickerMakeProtocolDate.Value.AddMonths(1).Date;
            modelSJCKHTTab.SJCKHTDJDate = System.DateTime.Now.Date;

            modelSJCKHTTab.InvoiceNo = "";
            modelSJCKHTTab.InvoiceNote = "";

            modelSJCKHTTab.QDPlaceTabID = 1;
         //   modelSJCKHTTab.YSMethodTabID = 1;
            modelSJCKHTTab.MDCountryTabID = 1;
            modelSJCKHTTab.PaidanRegisterTabID = nPaidanRegisterTabID;

            modelSJCKHTTab.BaoXian = @"由买方负责投保";
            modelSJCKHTTab.FKCondition = @"卖方发货后120天内电汇付款。";
            modelSJCKHTTab.SPCheck = @"由卖方申请，并保证按商检部门规定执行。";
            modelSJCKHTTab.ZYMethod = @"由双方协商解决或交由签约地有管辖权法院裁决。";
            modelSJCKHTTab.QTThing = @"由双方协商解决。";
            ds = m_bllBYBackQingDanTab.GetBackQingInfoByID("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                string strTemp = ds.Tables[0].Rows[0]["出口方式"].ToString();
                if (strTemp == "只到香港不再出口")
                {
                    modelSJCKHTTab.MDCountryTabID = 23;
                }

            }
           // m_bllSJCKHTTab.Add(modelSJCKHTTab);
            m_bllSJCKHTTab.TransAdd(modelSJCKHTTab, m_SQLStringList, m_arrayList);
            return;
        }

        private void AddTYInvoiceTabRecAfterTrans(int nPaidanRegisterTabID, int nYSMethodTabID)
        {
            DataSet ds = m_bllTYInvoiceTab.GetList("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return;
            }
            
            //int nBGDComeBackTabID = 0;
            //ds = m_bllBGDComeBackTab.GetList("PaidanRegisterTabID = '" + nPaidanRegisterTabID.ToString() + "'");
            //if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            //{
            //    nBGDComeBackTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["BGDComeBackTabID"].ToString(), 10);
            //}
            //进出口统一发票
            DGBY.Model.TYInvoiceTab modelTYInvoiceTab = new DGBY.Model.TYInvoiceTab();
            modelTYInvoiceTab.PaidanRegisterTabID = nPaidanRegisterTabID;
            modelTYInvoiceTab.ZhuanYPort = "";
            if(this.comboBoxPort.Text != "东莞")
                modelTYInvoiceTab.JieHuiFSTabID = 1;
            else
                modelTYInvoiceTab.JieHuiFSTabID = 2;
            modelTYInvoiceTab.MaoYiFSTabID = 1;
            modelTYInvoiceTab.Note = "";
            modelTYInvoiceTab.LCNo = "";
            modelTYInvoiceTab.KPDate = System.DateTime.Now;
            modelTYInvoiceTab.BYCompBankCountTabID = 1;
            modelTYInvoiceTab.IsPrint = 0;
            modelTYInvoiceTab.PrintDate = DateTime.Parse("1900-01-01");
            modelTYInvoiceTab.YSMethodTabID = nYSMethodTabID;
            m_bllTYInvoiceTab.TransAdd(modelTYInvoiceTab, m_SQLStringList, m_arrayList);
        }
        //增加报关装箱单记录,这个不能放到事务里，因为需要先生成商检装箱单ID
        private int AddBGPackingRec(int nPaidanRegisterTabID, long nSjDjNo
            , DGBY.Model.SJPackingTab modelSJPackingTabNew)
        {

            DGBY.Model.BGPackingTab modelBGPackingTab = new DGBY.Model.BGPackingTab();

            modelBGPackingTab.Note = this.textBoxNote.Text;
            modelBGPackingTab.ShoeBrand = this.textBoxMark.Text;
            modelBGPackingTab.ShipMarks = this.textBoxMaiTou.Text;

            modelBGPackingTab.DingCangNo = "";
            modelBGPackingTab.ShipName = "";
            modelBGPackingTab.HangCi = "";
            modelBGPackingTab.GuiNo = "";
            modelBGPackingTab.FengTiao = "";

            //DataSet ds = m_bllSJPackingTab.ShowOneSJPackRec("SJPackingTab.SJPackDJNo = '" + nSjDjNo + "'");

            //modelBGPackingTab.SJPackingTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["SJPackingTabID"].ToString(), 10);
            modelBGPackingTab.SJPackingTabID = 0;
            modelBGPackingTab.BGSJPackDJNo = nSjDjNo;

            modelBGPackingTab.IsShoePack = this.checkBoxIsShoe.Checked ? "是" : "否";
            modelBGPackingTab.BGPackDJDate = System.DateTime.Now.Date;

            modelBGPackingTab.BGPackDJNo = MakeBGPackDJNo();
            //if (this.comboBoxCoinUnit2.SelectedValue != null)
            //    modelBGPackingTab.BiZhiTabID = Convert.ToInt32(this.comboBoxCoinUnit2.SelectedValue.ToString(), 10);
            //if (this.comboBoxRecvGoodsComp.SelectedValue != null)
            //    modelBGPackingTab.SHCompTabID = Convert.ToInt32(this.comboBoxRecvGoodsComp.SelectedValue.ToString(), 10);
            //if (this.comboBoxStartCountry.SelectedValue != null)
            //    modelBGPackingTab.QYCountryTabID = Convert.ToInt32(this.comboBoxStartCountry.SelectedValue.ToString(), 10);
            //if (this.comboBoxPort.SelectedValue != null)
            //    modelBGPackingTab.ZYHarborTabID = Convert.ToInt32(this.comboBoxPort.SelectedValue.ToString(), 10);
            //if (this.comboBoxOutSideCate.SelectedValue != null)
            //    modelBGPackingTab.BZSortTabID = Convert.ToInt32(this.comboBoxOutSideCate.SelectedValue.ToString(), 10);
          //  if (this.comboBoxContractNo.SelectedValue != null)
                modelBGPackingTab.PaidanRegisterTabID = nPaidanRegisterTabID;


                modelBGPackingTab.BiZhiTabID = modelSJPackingTabNew.BiZhiTabID;

                modelBGPackingTab.SHCompTabID = modelSJPackingTabNew.SHCompTabID;

                modelBGPackingTab.QYCountryTabID = modelSJPackingTabNew.QYCountryTabID;

                modelBGPackingTab.ZYHarborTabID = modelSJPackingTabNew.ZYHarborTabID;

                modelBGPackingTab.BZSortTabID = modelSJPackingTabNew.BZSortTabID;

            modelBGPackingTab.BGHarborTabID = 1;
            modelBGPackingTab.GuiXingTabID = 6;
            modelBGPackingTab.BGHDataTabID = 33;
            return m_bllBGPackingTab.Add(modelBGPackingTab);
        }
        //增加报关装箱单记录,这个不能放到事务里，因为需要先生成商检装箱单ID
        private void AddBGPackingRecAfterTrans(int nPaidanRegisterTabID, long nSjDjNo)
        {
            
            DGBY.Model.BGPackingTab modelBGPackingTab = new DGBY.Model.BGPackingTab();

            modelBGPackingTab.Note = this.textBoxNote.Text;
            modelBGPackingTab.ShoeBrand = this.textBoxMark.Text;
            modelBGPackingTab.ShipMarks = this.textBoxMaiTou.Text;

            modelBGPackingTab.DingCangNo = "";
            modelBGPackingTab.ShipName = "";
            modelBGPackingTab.HangCi = "";
            modelBGPackingTab.GuiNo = "";
            modelBGPackingTab.FengTiao = "";

            //DataSet ds = m_bllSJPackingTab.ShowOneSJPackRec("SJPackingTab.SJPackDJNo = '" + nSjDjNo + "'");

            //modelBGPackingTab.SJPackingTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["SJPackingTabID"].ToString(), 10);
            modelBGPackingTab.SJPackingTabID = 0;
            modelBGPackingTab.BGSJPackDJNo = nSjDjNo;

            modelBGPackingTab.IsShoePack = this.checkBoxIsShoe.Checked ? "是" : "否";
            modelBGPackingTab.BGPackDJDate = System.DateTime.Now.Date;

            modelBGPackingTab.BGPackDJNo = MakeBGPackDJNo();
            if (this.comboBoxCoinUnit2.SelectedValue != null)
                modelBGPackingTab.BiZhiTabID = Convert.ToInt32(this.comboBoxCoinUnit2.SelectedValue.ToString(), 10);
            if (this.comboBoxRecvGoodsComp.SelectedValue != null)
                modelBGPackingTab.SHCompTabID = Convert.ToInt32(this.comboBoxRecvGoodsComp.SelectedValue.ToString(), 10);
            if (this.comboBoxStartCountry.SelectedValue != null)
                modelBGPackingTab.QYCountryTabID = Convert.ToInt32(this.comboBoxStartCountry.SelectedValue.ToString(), 10);
            if (this.comboBoxPort.SelectedValue != null)
                modelBGPackingTab.ZYHarborTabID = Convert.ToInt32(this.comboBoxPort.SelectedValue.ToString(), 10);
            if (this.comboBoxOutSideCate.SelectedValue != null)
                modelBGPackingTab.BZSortTabID = Convert.ToInt32(this.comboBoxOutSideCate.SelectedValue.ToString(), 10);
            //if (this.comboBoxContractNo.SelectedValue != null)
                modelBGPackingTab.PaidanRegisterTabID = nPaidanRegisterTabID;

            modelBGPackingTab.BGHarborTabID = 1;

            modelBGPackingTab.GuiXingTabID = 6;
            modelBGPackingTab.BGHDataTabID = 33;

            m_bllBGPackingTab.TransAdd(modelBGPackingTab, m_SQLStringList, m_arrayList);
        }
        private Int64 MakeRecvMoneyDetailDJNo()
        {
            string strDate = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString().PadLeft(2, '0') + System.DateTime.Now.Day.ToString().PadLeft(2, '0');
            DataSet ds = m_bllFinCheckInvoiceRecordDetailTab_New.GetSJPackDJNoByDate("DanJuDate = '" + strDate + "'");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                string strDJNo = ds.Tables[0].Rows[0]["MaxJPackDJNum"].ToString();
                long nDJNo = 0;
                if (strDJNo != "")
                    nDJNo = Convert.ToInt64(strDJNo, 10);
                nDJNo++;
                string strTemp = "";
                if (strDJNo != "")
                    strTemp = string.Format("{0:d4}", nDJNo);
                else
                    strTemp = strDate + string.Format("{0:d4}", nDJNo);

                return Convert.ToInt64(strTemp, 10);
            }

            return 0;
        }
        private void AddFeeDHLTruePayTab(int nPaidanRegisterTabID)
        {
            DataSet ds = m_bllFeeDHLTruePayTab.GetListInfo("FeeDHLTruePayTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return;
            }

            ds = m_bllPaidanRegisterTab.GetListInfo("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");


            DGBY.Model.FeeDHLTruePayTab modelFeeDHLTruePayTab = new DGBY.Model.FeeDHLTruePayTab();
            modelFeeDHLTruePayTab.FactoryDataTabID = (int)ds.Tables[0].Rows[0]["FactoryDataTabID"];
            
            modelFeeDHLTruePayTab.PaidanRegisterTabID = nPaidanRegisterTabID;
            modelFeeDHLTruePayTab.ToPubBianHao = "";
            modelFeeDHLTruePayTab.ToPrivateBianHao = "";

            //modelFeeSJTruePayTab.TruePayDate = DateTime.Parse("1900-01-01");
            //modelFeeSJTruePayTab.InputDate = DateTime.Parse("1900-01-01"); 
            modelFeeDHLTruePayTab.TruePayMonth = 0;
            modelFeeDHLTruePayTab.ShouldPayMonth = 0;
            modelFeeDHLTruePayTab.ShouldRecvNotRecvMoney = 0;

            modelFeeDHLTruePayTab.ToPubFormula = "";
            modelFeeDHLTruePayTab.ToPrivateFormula = "";
            modelFeeDHLTruePayTab.DHLCompany = "DHL";
            modelFeeDHLTruePayTab.JinBanPerson = "";
            modelFeeDHLTruePayTab.RecvMonyePerson = "";

            modelFeeDHLTruePayTab.IsToRecvPayTab = 0;
            modelFeeDHLTruePayTab.IsToFinCheckMoneyTab = 0;
            modelFeeDHLTruePayTab.Note = "";
            modelFeeDHLTruePayTab.SjDate = System.DateTime.Now.Date;
            modelFeeDHLTruePayTab.DHLCountryTabID = 1;

            modelFeeDHLTruePayTab.bitFiledReserv1 = false;
            modelFeeDHLTruePayTab.bitFiledReserv2 = false;

            modelFeeDHLTruePayTab.stringFiledReserv1 = "";
            modelFeeDHLTruePayTab.stringFiledReserv2 = "";
            modelFeeDHLTruePayTab.stringFiledReserv3 = "";
            modelFeeDHLTruePayTab.stringFiledReserv4 = "";

            modelFeeDHLTruePayTab.intFiledReserv1 = (int)ds.Tables[0].Rows[0]["UserPasswordTabID"]; //制单人员
            modelFeeDHLTruePayTab.intFiledReserv2 = 0;
            modelFeeDHLTruePayTab.intFiledReserv3 = 0;
            modelFeeDHLTruePayTab.intFiledReserv4 = 0;
            modelFeeDHLTruePayTab.datetimeFiledReserv1 = System.DateTime.Now.Date;
            modelFeeDHLTruePayTab.datetimeFiledReserv2 = System.DateTime.Now.Date;

            modelFeeDHLTruePayTab.decimalFiledReserv1 = 0;
            modelFeeDHLTruePayTab.decimalFiledReserv2 = 0;
            modelFeeDHLTruePayTab.decimalFiledReserv3 = 0;
            modelFeeDHLTruePayTab.decimalFiledReserv4 = 0;

            m_bllFeeDHLTruePayTab.TransAdd(modelFeeDHLTruePayTab, m_SQLStringList, m_arrayList);

        }
        //private void AddFeeZXZTruePayTab(int nPaidanRegisterTabID)
        //{
        //    DataSet ds = m_bllFeeZXZTruePayTab.GetList("FeeZXZTruePayTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

        //    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
        //    {
        //        return;
        //    }



        //    DGBY.Model.FeeZXZTruePayTab modelFeeZXZTruePayTab = new DGBY.Model.FeeZXZTruePayTab();

        //    modelFeeZXZTruePayTab.PaidanRegisterTabID = nPaidanRegisterTabID;
        //    modelFeeZXZTruePayTab.ToPubBianHao = "";
        //    modelFeeZXZTruePayTab.ToPrivateBianHao = "";

        //    //modelFeeSJTruePayTab.TruePayDate = DateTime.Parse("1900-01-01");
        //    //modelFeeSJTruePayTab.InputDate = DateTime.Parse("1900-01-01"); 
        //    modelFeeZXZTruePayTab.TruePayMonth = 0;
        //    modelFeeZXZTruePayTab.ShouldPayMonth = 0;
        //    modelFeeZXZTruePayTab.ShouldRecvNotRecvMoney = 0;

        //    modelFeeZXZTruePayTab.ToPubFormula = "";
        //    modelFeeZXZTruePayTab.ToPrivateFormula = "";
        //    modelFeeZXZTruePayTab.ZXZCompany = "";
        //    modelFeeZXZTruePayTab.JinBanPerson = "";
        //    modelFeeZXZTruePayTab.RecvMonyePerson = "";

        //    modelFeeZXZTruePayTab.IsToRecvPayTab = 0;
        //    modelFeeZXZTruePayTab.IsToFinCheckMoneyTab = 0;
        //    modelFeeZXZTruePayTab.Note = "";
        //    modelFeeZXZTruePayTab.SjDate = System.DateTime.Now.Date;
        //    m_bllFeeZXZTruePayTab.TransAdd(modelFeeZXZTruePayTab, m_SQLStringList, m_arrayList);

        //}
        //private void AddFeeJCFTruePayTab(int nPaidanRegisterTabID)
        //{
        //    DataSet ds = m_bllFeeJCFTruePayTab.GetList("FeeJCFTruePayTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

        //    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
        //    {
        //        return;
        //    }



        //    DGBY.Model.FeeJCFTruePayTab modelFeeJCFTruePayTab = new DGBY.Model.FeeJCFTruePayTab();

        //    modelFeeJCFTruePayTab.PaidanRegisterTabID = nPaidanRegisterTabID;
        //    modelFeeJCFTruePayTab.ToPubBianHao = "";
        //    modelFeeJCFTruePayTab.ToPrivateBianHao = "";

        //    //modelFeeSJTruePayTab.TruePayDate = DateTime.Parse("1900-01-01");
        //    //modelFeeSJTruePayTab.InputDate = DateTime.Parse("1900-01-01"); 
        //    modelFeeJCFTruePayTab.TruePayMonth = 0;
        //    modelFeeJCFTruePayTab.ShouldPayMonth = 0;
        //    modelFeeJCFTruePayTab.ShouldRecvNotRecvMoney = 0;

        //    modelFeeJCFTruePayTab.ToPubFormula = "";
        //    modelFeeJCFTruePayTab.ToPrivateFormula = "";
        //    modelFeeJCFTruePayTab.JCFCompany = "";
        //    modelFeeJCFTruePayTab.JinBanPerson = "";
        //    modelFeeJCFTruePayTab.RecvMonyePerson = "";

        //    modelFeeJCFTruePayTab.IsToRecvPayTab = 0;
        //    modelFeeJCFTruePayTab.IsToFinCheckMoneyTab = 0;
        //    modelFeeJCFTruePayTab.Note = "";
        //    modelFeeJCFTruePayTab.SjDate = System.DateTime.Now.Date;
        //    m_bllFeeJCFTruePayTab.TransAdd(modelFeeJCFTruePayTab, m_SQLStringList, m_arrayList);

        //}
        private void AddFeeSJTruePayTab(int nPaidanRegisterTabID)
        {
            DataSet ds = m_bllFeeSJTruePayTab.GetListInfo("FeeSJTruePayTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return;
            }

            ds = m_bllPaidanRegisterTab.GetListInfo("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

            

            DGBY.Model.FeeSJTruePayTab modelFeeSJTruePayTab = new DGBY.Model.FeeSJTruePayTab();

            modelFeeSJTruePayTab.FactoryDataTabID = (int)ds.Tables[0].Rows[0]["FactoryDataTabID"];
            modelFeeSJTruePayTab.BYCompanyTabID = (int)ds.Tables[0].Rows[0]["BYCompanyTabID"];
            modelFeeSJTruePayTab.BYDepartTabID = (int)ds.Tables[0].Rows[0]["BYDepartTabID"];

            modelFeeSJTruePayTab.PaidanRegisterTabID = nPaidanRegisterTabID;
            modelFeeSJTruePayTab.ToPubBianHao = "";
            modelFeeSJTruePayTab.ToPrivateBianHao = "";

            //modelFeeSJTruePayTab.TruePayDate = DateTime.Parse("1900-01-01");
            //modelFeeSJTruePayTab.InputDate = DateTime.Parse("1900-01-01"); 
            modelFeeSJTruePayTab.TruePayMonth = 0;
            modelFeeSJTruePayTab.ShouldPayMonth = 0;
            modelFeeSJTruePayTab.ShouldRecvNotRecvMoney = 0;
            modelFeeSJTruePayTab.ShouldRecvMoney = 0;
       
            modelFeeSJTruePayTab.ToPubFormula = "";
            modelFeeSJTruePayTab.ToPrivateFormula = "";
                                   
            modelFeeSJTruePayTab.JinBanPerson = "";
            modelFeeSJTruePayTab.RecvMonyePerson = "";

            modelFeeSJTruePayTab.IsToRecvPayTab = 0;
            modelFeeSJTruePayTab.IsToFinCheckMoneyTab = 0;
            modelFeeSJTruePayTab.Note = "";
            modelFeeSJTruePayTab.SjDate = System.DateTime.Now.Date;

            modelFeeSJTruePayTab.bitFiledReserv1 = false;
            modelFeeSJTruePayTab.bitFiledReserv2 = false;

            modelFeeSJTruePayTab.stringFiledReserv1 = "";
            modelFeeSJTruePayTab.stringFiledReserv2 = "";
            modelFeeSJTruePayTab.stringFiledReserv3 = "";
            modelFeeSJTruePayTab.stringFiledReserv4 = "";

            modelFeeSJTruePayTab.intFiledReserv1 = 0;
            modelFeeSJTruePayTab.intFiledReserv2 = 0;
            modelFeeSJTruePayTab.intFiledReserv3 = 0;

            modelFeeSJTruePayTab.datetimeFiledReserv1 = System.DateTime.Now.Date;
            modelFeeSJTruePayTab.datetimeFiledReserv2 = System.DateTime.Now.Date;

            modelFeeSJTruePayTab.decimalFiledReserv1 = 0;
            modelFeeSJTruePayTab.decimalFiledReserv2 = 0;
            modelFeeSJTruePayTab.decimalFiledReserv3 = 0;
            modelFeeSJTruePayTab.decimalFiledReserv4 = 0;

            m_bllFeeSJTruePayTab.TransAdd(modelFeeSJTruePayTab, m_SQLStringList, m_arrayList);

        }

        private void AddFacFeeTab(int nPaidanRegisterTabID)
        {
            //return;
            DataSet ds = m_bllFacFeeTabNew.GetList("FacFeeTabNew.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return;
            }

            DGBY.Model.FacFeeTabNew modelFacFeeTabNew = new DGBY.Model.FacFeeTabNew();

            modelFacFeeTabNew.PaidanRegisterTabID = nPaidanRegisterTabID;





            m_bllFacFeeTabNew.TransAdd(modelFacFeeTabNew, m_SQLStringList, m_arrayList);


           
        }

        private void AddFinCheckInvoiceRecordDetailTabNewAfterTrans(int nPaidanRegisterTabID)
        {
            DataSet ds = m_bllFinCheckInvoiceRecordDetailTab_New.GetList("FinCheckInvoiceRecordDetailTab_New.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return;
            }

            //int nBGDComeBackTabID = 0;
            //ds = m_bllBGDComeBackTab.GetList("PaidanRegisterTabID = '" + nPaidanRegisterTabID.ToString() + "'");
            //if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            //{
            //    nBGDComeBackTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["BGDComeBackTabID"].ToString(), 10);
            //}
            //进出口统一发票
            DGBY.Model.FinCheckInvoiceRecordDetailTab_New modelFinCheckInvoiceRecordDetailTab_New = new DGBY.Model.FinCheckInvoiceRecordDetailTab_New();
            modelFinCheckInvoiceRecordDetailTab_New.PaidanRegisterTabID = nPaidanRegisterTabID;
            modelFinCheckInvoiceRecordDetailTab_New.ShenPiaoDate = null; 
            modelFinCheckInvoiceRecordDetailTab_New.DanJuDate = null;
            modelFinCheckInvoiceRecordDetailTab_New.TuiPiaoReason = "";
            modelFinCheckInvoiceRecordDetailTab_New.Note = "";
            modelFinCheckInvoiceRecordDetailTab_New.USDPercent17 = 0;
            modelFinCheckInvoiceRecordDetailTab_New.USDPercent16 = 0;
            modelFinCheckInvoiceRecordDetailTab_New.USDPercent15 = 0;
            modelFinCheckInvoiceRecordDetailTab_New.USDPercent13 = 0;
            modelFinCheckInvoiceRecordDetailTab_New.USDPercent9 = 0;
            modelFinCheckInvoiceRecordDetailTab_New.USDPercent5 = 0;

            modelFinCheckInvoiceRecordDetailTab_New.HKPercent17 = 0;
            modelFinCheckInvoiceRecordDetailTab_New.HKPercent16 = 0;
            modelFinCheckInvoiceRecordDetailTab_New.HKPercent15 = 0;
            modelFinCheckInvoiceRecordDetailTab_New.HKPercent13 = 0;
            modelFinCheckInvoiceRecordDetailTab_New.HKPercent9 = 0;
            modelFinCheckInvoiceRecordDetailTab_New.HKPercent5 = 0;

            modelFinCheckInvoiceRecordDetailTab_New.HKHuiLv = 0;
            modelFinCheckInvoiceRecordDetailTab_New.USDHuiLv = 0;

            modelFinCheckInvoiceRecordDetailTab_New.IsPayTaxDone = 0;
            modelFinCheckInvoiceRecordDetailTab_New.USDJinE = 0;
            modelFinCheckInvoiceRecordDetailTab_New.SetPercent = (decimal)0.17;
            modelFinCheckInvoiceRecordDetailTab_New.TransGongShi = "";
            modelFinCheckInvoiceRecordDetailTab_New.BianHao = ""; 
  
            m_bllFinCheckInvoiceRecordDetailTab_New.TransAdd(modelFinCheckInvoiceRecordDetailTab_New, m_SQLStringList, m_arrayList);
        }

        private void AddFinInvoiceRecordTabNewAfterTrans(int nPaidanRegisterTabID)
        {
            DataSet ds = m_bllFinInvoiceRecordTab_New.GetList("FinInvoiceRecordTab_New.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return;
            }
            Decimal dtBackTaxPoint = 0;
            DataSet dsInfo = m_bllFactoryGoodsTab.GetGoodsBandInfo("PaidanRegisterTab.PaidanRegisterTabID = '"
                + nPaidanRegisterTabID.ToString() + "'");
            if (dsInfo.Tables.Count > 0 && dsInfo.Tables[0].Rows.Count > 0)
            {
                dtBackTaxPoint = Convert.ToDecimal(dsInfo.Tables[0].Rows[0]["退税点"].ToString());
            }
            int nFormulaSelector = 0;
            Decimal dtFactorA = 0;
            dsInfo = m_bllFactoryDataTab.GetFactorAInfo("PaidanRegisterTab.PaidanRegisterTabID = '"
                + nPaidanRegisterTabID.ToString() + "'");
            if (dsInfo.Tables.Count > 0 && dsInfo.Tables[0].Rows.Count > 0)
            {
                dtFactorA = Convert.ToDecimal(dsInfo.Tables[0].Rows[0]["系数A"].ToString());
                nFormulaSelector = Convert.ToInt32(dsInfo.Tables[0].Rows[0]["公式选择"].ToString(), 10);

            }
            //int nBGDComeBackTabID = 0;
            //ds = m_bllBGDComeBackTab.GetList("PaidanRegisterTabID = '" + nPaidanRegisterTabID.ToString() + "'");
            //if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            //{
            //    nBGDComeBackTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["BGDComeBackTabID"].ToString(), 10);
            //}
            //进出口统一发票
            DGBY.Model.FinInvoiceRecordTab_New modelFinInvoiceRecordTab_New = new DGBY.Model.FinInvoiceRecordTab_New();
            modelFinInvoiceRecordTab_New.PaidanRegisterTabID = nPaidanRegisterTabID;
            modelFinInvoiceRecordTab_New.KaiPiaoHuiLv = 0;
            modelFinInvoiceRecordTab_New.KaiPiaoDate = null;
            modelFinInvoiceRecordTab_New.InvoiceNo = "";
            modelFinInvoiceRecordTab_New.JinE = 0;
            modelFinInvoiceRecordTab_New.ShuiJin = 0;
            modelFinInvoiceRecordTab_New.ChuKouYearMonth = "";
            modelFinInvoiceRecordTab_New.LuDanDate = null;
            modelFinInvoiceRecordTab_New.BackTaxPoint = dtBackTaxPoint;
            modelFinInvoiceRecordTab_New.FactorA = dtFactorA;
            modelFinInvoiceRecordTab_New.FactorB = 1.17M;
            modelFinInvoiceRecordTab_New.PriceTaxFormulaSelector = nFormulaSelector;
            modelFinInvoiceRecordTab_New.JinECheckIgnore = 0;
            modelFinInvoiceRecordTab_New.IsGouHouContractPrint = "否";
            modelFinInvoiceRecordTab_New.IsKaiPiaoFinish = 0;

            m_bllFinInvoiceRecordTab_New.TransAdd(modelFinInvoiceRecordTab_New, m_SQLStringList, m_arrayList);
        }
        private void AddOtherSheetRec(int nPaidanRegisterTabID, bool bIsDisCount, ref int nYSMethodTabID)
        {
            AddOneSjCKContractRec(nPaidanRegisterTabID, bIsDisCount);
  
            AddOneSjGHContractRec(nPaidanRegisterTabID);
            AddOneBGCKContractRec(nPaidanRegisterTabID, bIsDisCount, ref nYSMethodTabID);
           // AddOneBackBGDRec(nPaidanRegisterTabID);
       

            return;

        }
        private Int64 MakeBGContractDJNo()
        {
            string strDate = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString().PadLeft(2, '0') + System.DateTime.Now.Day.ToString().PadLeft(2, '0');
            DataSet ds = m_bllBGCKHTTab.GetBGPackDJNoByDate("BGCKHTDJDate = '" + strDate + "'");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                string strDJNo = ds.Tables[0].Rows[0]["MaxBGDJNum"].ToString();
                long nDJNo = 0;
                if (strDJNo != "")
                    nDJNo = Convert.ToInt64(strDJNo, 10);
                nDJNo++;
                string strTemp = "";
                if (strDJNo != "")
                    strTemp = string.Format("{0:d4}", nDJNo);
                else
                    strTemp = strDate + string.Format("{0:d4}", nDJNo);

                return Convert.ToInt64(strTemp, 10);
            }

            return 0;
        }
        private Int64 MakeBGPackDJNo()
        {
            string strDate = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString().PadLeft(2, '0') + System.DateTime.Now.Day.ToString().PadLeft(2, '0');
            DataSet ds = m_bllBGPackingTab.GetSJPackDJNoByDate("BGPackDJDate = '" + strDate + "'");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                string strDJNo = ds.Tables[0].Rows[0]["MaxJPackDJNum"].ToString();
                long nDJNo = 0;
                if (strDJNo != "")
                    nDJNo = Convert.ToInt64(strDJNo, 10);
                nDJNo++;
                string strTemp = "";
                if (strDJNo != "")
                    strTemp = string.Format("{0:d4}", nDJNo);
                else
                    strTemp = strDate + string.Format("{0:d4}", nDJNo);

                return Convert.ToInt64(strTemp, 10);
            }

            return 0;
        }

        private void AddFeeDLCWTruePayTab(int nPaidanRegisterTabID)
        {
            DataSet ds = m_bllFeeDLCWTruePayTab.GetListInfo("FeeDLCWTruePayTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return;
            }

            ds = m_bllPaidanRegisterTab.GetListInfo("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");


            DGBY.Model.FeeDLCWTruePayTab modelFeeDLCWTruePayTab = new DGBY.Model.FeeDLCWTruePayTab();
            modelFeeDLCWTruePayTab.FactoryDataTabID = (int)ds.Tables[0].Rows[0]["FactoryDataTabID"];




            modelFeeDLCWTruePayTab.PaidanRegisterTabID = nPaidanRegisterTabID;
            modelFeeDLCWTruePayTab.ToPubBianHao = "";
            modelFeeDLCWTruePayTab.ToPrivateBianHao = "";
            modelFeeDLCWTruePayTab.SBDate = DateTime.Parse("1900-01-01");
            //modelFeeBGTruePayTab.TruePayDate = DateTime.Parse("1900-01-01");
            //modelFeeBGTruePayTab.InputDate = DateTime.Parse("1900-01-01"); 
            modelFeeDLCWTruePayTab.TruePayMonth = 0;
            modelFeeDLCWTruePayTab.ShouldPayMonth = 0;
            modelFeeDLCWTruePayTab.TruePayMoney = 0;


            modelFeeDLCWTruePayTab.ToPubFormula = "";
            modelFeeDLCWTruePayTab.ToPrivateFormula = "";
             
            modelFeeDLCWTruePayTab.JinBanPerson = "";
            modelFeeDLCWTruePayTab.RecvMonyePerson = "";

            modelFeeDLCWTruePayTab.IsToRecvPayTab = 0;
            modelFeeDLCWTruePayTab.IsToFinCheckMoneyTab = 0;
            modelFeeDLCWTruePayTab.Note = "";

            modelFeeDLCWTruePayTab.TruePayMoney = 0;
            modelFeeDLCWTruePayTab.ShouldRecvMoney = 0;

            modelFeeDLCWTruePayTab.bitFiledReserv1 = false;
            modelFeeDLCWTruePayTab.bitFiledReserv2 = false;

            modelFeeDLCWTruePayTab.stringFiledReserv1 = "";
            modelFeeDLCWTruePayTab.stringFiledReserv2 = "";
            modelFeeDLCWTruePayTab.stringFiledReserv3 = "";
            modelFeeDLCWTruePayTab.stringFiledReserv4 = "";

            modelFeeDLCWTruePayTab.intFiledReserv1 = (int)ds.Tables[0].Rows[0]["UserPasswordTabID"]; //制单人员
            modelFeeDLCWTruePayTab.intFiledReserv2 = 3;
            modelFeeDLCWTruePayTab.intFiledReserv3 = 0;
            // modelFeeDLCWTruePayTab.intFiledReserv4 = 0;
            modelFeeDLCWTruePayTab.datetimeFiledReserv1 = DateTime.Parse("1900-01-01");
            modelFeeDLCWTruePayTab.datetimeFiledReserv2 = System.DateTime.Now.Date;

            modelFeeDLCWTruePayTab.decimalFiledReserv1 = 0;
            modelFeeDLCWTruePayTab.decimalFiledReserv2 = 0;
            modelFeeDLCWTruePayTab.decimalFiledReserv3 = 0;
            modelFeeDLCWTruePayTab.decimalFiledReserv4 = 0;

            // modelFeeBGTruePayTab.SjDate = System.DateTime.Now.Date;
            m_bllFeeDLCWTruePayTab.TransAdd(modelFeeDLCWTruePayTab, m_SQLStringList, m_arrayList);

        }
        private void AddFeeHKYSTruePayTab(int nPaidanRegisterTabID)
        {
            DataSet ds = m_bllFeeHKYSTruePayTab.GetListInfo("FeeHKYSTruePayTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return;
            }



            DGBY.Model.FeeHKYSTruePayTab modelFeeHKYSTruePayTab = new DGBY.Model.FeeHKYSTruePayTab();

            modelFeeHKYSTruePayTab.PaidanRegisterTabID = nPaidanRegisterTabID;
            modelFeeHKYSTruePayTab.BiZhiTabID = 1;
            modelFeeHKYSTruePayTab.ToPubBianHao = "";
            modelFeeHKYSTruePayTab.ToPrivateBianHao = "";
            modelFeeHKYSTruePayTab.SBDate = DateTime.Parse("1900-01-01");
            //modelFeeBGTruePayTab.TruePayDate = DateTime.Parse("1900-01-01");
            //modelFeeBGTruePayTab.InputDate = DateTime.Parse("1900-01-01"); 
            modelFeeHKYSTruePayTab.TruePayMonth = 0;
            modelFeeHKYSTruePayTab.ShouldPayMonth = 0;
            //modelFeeHKYSTruePayTab.TruePayMoney = 0;
            modelFeeHKYSTruePayTab.TruePayHuiLv = 0;
            modelFeeHKYSTruePayTab.TruePayMoneyWB = 0;
            modelFeeHKYSTruePayTab.TruePaySXFeeWB = 50;
            modelFeeHKYSTruePayTab.TrueRecvHuiLv = 0;
            modelFeeHKYSTruePayTab.TrueRecvKDFeeRMB = 30;


            //modelFeeHKYSTruePayTab.ToPubFormula = "";
            //modelFeeHKYSTruePayTab.ToPrivateFormula = "";

            modelFeeHKYSTruePayTab.JinBanPerson = "";
            modelFeeHKYSTruePayTab.RecvMonyePerson = "";

            modelFeeHKYSTruePayTab.IsToRecvPayTab = 0;
            modelFeeHKYSTruePayTab.IsToFinCheckMoneyTab = 0;
            modelFeeHKYSTruePayTab.Note = "";

            modelFeeHKYSTruePayTab.bitFiledReserv1 = false;
            modelFeeHKYSTruePayTab.bitFiledReserv2 = false;

            modelFeeHKYSTruePayTab.stringFiledReserv1 = "";
            modelFeeHKYSTruePayTab.stringFiledReserv2 = "";
            modelFeeHKYSTruePayTab.stringFiledReserv3 = "";
            modelFeeHKYSTruePayTab.stringFiledReserv4 = "";

            modelFeeHKYSTruePayTab.intFiledReserv1 = 0;
            modelFeeHKYSTruePayTab.intFiledReserv2 = 0;
            modelFeeHKYSTruePayTab.intFiledReserv3 = 0;
            modelFeeHKYSTruePayTab.intFiledReserv4 = 0;
            // modelFeeHKYSTruePayTab.intFiledReserv4 = 0;
            modelFeeHKYSTruePayTab.datetimeFiledReserv1 = System.DateTime.Now.Date;
            modelFeeHKYSTruePayTab.datetimeFiledReserv2 = System.DateTime.Now.Date;

            modelFeeHKYSTruePayTab.decimalFiledReserv1 = 0;
            modelFeeHKYSTruePayTab.decimalFiledReserv2 = 0;
            modelFeeHKYSTruePayTab.decimalFiledReserv3 = 0;
            modelFeeHKYSTruePayTab.decimalFiledReserv4 = 0;
            // modelFeeBGTruePayTab.SjDate = System.DateTime.Now.Date;
            m_bllFeeHKYSTruePayTab.TransAdd(modelFeeHKYSTruePayTab, m_SQLStringList, m_arrayList);

        }
        private void AddFeeDZTruePayTab(int nPaidanRegisterTabID)
        {
            DataSet ds = m_bllFeeDZTruePayTab.GetListInfo("FeeDZTruePayTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return;
            }

            ds = m_bllPaidanRegisterTab.GetListInfo("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");


            DGBY.Model.FeeDZTruePayTab modelFeeDZTruePayTab = new DGBY.Model.FeeDZTruePayTab();
            modelFeeDZTruePayTab.FactoryDataTabID = (int)ds.Tables[0].Rows[0]["FactoryDataTabID"];




            modelFeeDZTruePayTab.PaidanRegisterTabID = nPaidanRegisterTabID;
            modelFeeDZTruePayTab.DZCompDataTabID = 1;
            modelFeeDZTruePayTab.DZCateTabID = 1;
            modelFeeDZTruePayTab.ToPubBianHao = "";
            modelFeeDZTruePayTab.ToPrivateBianHao = "";
            modelFeeDZTruePayTab.SBDate = DateTime.Parse("1900-01-01");
            //modelFeeBGTruePayTab.TruePayDate = DateTime.Parse("1900-01-01");
            //modelFeeBGTruePayTab.InputDate = DateTime.Parse("1900-01-01"); 
            modelFeeDZTruePayTab.TruePayMonth = 0;
            modelFeeDZTruePayTab.ShouldPayMonth = 0;
            //modelFeeDZTruePayTab.TruePayMoney = 0;
            modelFeeDZTruePayTab.DZCounts = 0;
            modelFeeDZTruePayTab.AddPageCounts = 0;
    


            //modelFeeDZTruePayTab.ToPubFormula = "";
            //modelFeeDZTruePayTab.ToPrivateFormula = "";

            modelFeeDZTruePayTab.JinBanPerson = "";
            modelFeeDZTruePayTab.RecvMonyePerson = "";

            modelFeeDZTruePayTab.IsToRecvPayTab = 0;
            modelFeeDZTruePayTab.IsToFinCheckMoneyTab = 0;
            modelFeeDZTruePayTab.Note = "";
            // modelFeeBGTruePayTab.SjDate = System.DateTime.Now.Date;

            modelFeeDZTruePayTab.bitFiledReserv1 = false;
            modelFeeDZTruePayTab.bitFiledReserv2 = false;

            modelFeeDZTruePayTab.stringFiledReserv1 = "";
            modelFeeDZTruePayTab.stringFiledReserv2 = "";
            modelFeeDZTruePayTab.stringFiledReserv3 = "";
            modelFeeDZTruePayTab.stringFiledReserv4 = "";

            modelFeeDZTruePayTab.intFiledReserv1 = (int)ds.Tables[0].Rows[0]["UserPasswordTabID"]; //制单人员
            modelFeeDZTruePayTab.intFiledReserv2 = 0;
            modelFeeDZTruePayTab.intFiledReserv3 = 0;
            modelFeeDZTruePayTab.intFiledReserv4 = 0;
            modelFeeDZTruePayTab.datetimeFiledReserv1 = System.DateTime.Parse("1900-01-01");//送单日期
            modelFeeDZTruePayTab.datetimeFiledReserv2 = System.DateTime.Now.Date;

            modelFeeDZTruePayTab.decimalFiledReserv1 = 0;
            modelFeeDZTruePayTab.decimalFiledReserv2 = 0;
            modelFeeDZTruePayTab.decimalFiledReserv3 = 0;
            modelFeeDZTruePayTab.decimalFiledReserv4 = 0;

            m_bllFeeDZTruePayTab.TransAdd(modelFeeDZTruePayTab, m_SQLStringList, m_arrayList);

        }
        private void AddFeeHKCWTruePayTab(int nPaidanRegisterTabID)
        {
            DataSet ds = m_bllFeeHKCWTruePayTab.GetListInfo("FeeHKCWTruePayTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return;
            }


            ds = m_bllPaidanRegisterTab.GetListInfo("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");
            DGBY.Model.FeeHKCWTruePayTab modelFeeHKCWTruePayTab = new DGBY.Model.FeeHKCWTruePayTab();
            modelFeeHKCWTruePayTab.FactoryDataTabID = (int)ds.Tables[0].Rows[0]["FactoryDataTabID"];



            modelFeeHKCWTruePayTab.PaidanRegisterTabID = nPaidanRegisterTabID;
            modelFeeHKCWTruePayTab.BiZhiTabID = 1;
            modelFeeHKCWTruePayTab.ToPubBianHao = "";
            modelFeeHKCWTruePayTab.ToPrivateBianHao = "";
            modelFeeHKCWTruePayTab.SBDate = DateTime.Parse("1900-01-01");
            //modelFeeBGTruePayTab.TruePayDate = DateTime.Parse("1900-01-01");
            //modelFeeBGTruePayTab.InputDate = DateTime.Parse("1900-01-01"); 
            modelFeeHKCWTruePayTab.TruePayMonth = 0;
            modelFeeHKCWTruePayTab.ShouldPayMonth = 0;
            //modelFeeHKCWTruePayTab.TruePayMoney = 0;
            modelFeeHKCWTruePayTab.TruePayHuiLv = 0;
            modelFeeHKCWTruePayTab.TruePayMoneyWB = 0;
            modelFeeHKCWTruePayTab.TruePaySXFeeWB = 50;
            modelFeeHKCWTruePayTab.TrueRecvHuiLv = 0;
            modelFeeHKCWTruePayTab.TrueRecvKDFeeRMB = 30;


            //modelFeeHKCWTruePayTab.ToPubFormula = "";
            //modelFeeHKCWTruePayTab.ToPrivateFormula = "";

            modelFeeHKCWTruePayTab.JinBanPerson = "";
            modelFeeHKCWTruePayTab.RecvMonyePerson = "";

            modelFeeHKCWTruePayTab.IsToRecvPayTab = 0;
            modelFeeHKCWTruePayTab.IsToFinCheckMoneyTab = 0;
            modelFeeHKCWTruePayTab.Note = "";
            // modelFeeBGTruePayTab.SjDate = System.DateTime.Now.Date;

            modelFeeHKCWTruePayTab.bitFiledReserv1 = false;
            modelFeeHKCWTruePayTab.bitFiledReserv2 = false;

            modelFeeHKCWTruePayTab.stringFiledReserv1 = "";
            modelFeeHKCWTruePayTab.stringFiledReserv2 = "";
            modelFeeHKCWTruePayTab.stringFiledReserv3 = "";
            modelFeeHKCWTruePayTab.stringFiledReserv4 = "";

            modelFeeHKCWTruePayTab.intFiledReserv1 = (int)ds.Tables[0].Rows[0]["UserPasswordTabID"]; //制单人员
            modelFeeHKCWTruePayTab.intFiledReserv2 = 0;
            modelFeeHKCWTruePayTab.intFiledReserv3 = 0;
            modelFeeHKCWTruePayTab.intFiledReserv4 = 0;
            modelFeeHKCWTruePayTab.datetimeFiledReserv1 = System.DateTime.Now.Date;
            modelFeeHKCWTruePayTab.datetimeFiledReserv2 = System.DateTime.Now.Date;

            modelFeeHKCWTruePayTab.decimalFiledReserv1 = 0;
            modelFeeHKCWTruePayTab.decimalFiledReserv2 = 0;
            modelFeeHKCWTruePayTab.decimalFiledReserv3 = 0;
            modelFeeHKCWTruePayTab.decimalFiledReserv4 = 0;

            m_bllFeeHKCWTruePayTab.TransAdd(modelFeeHKCWTruePayTab, m_SQLStringList, m_arrayList);

        }
        private void AddFeeBGTruePayTab(int nPaidanRegisterTabID)
        {
            DataSet ds = m_bllFeeBGTruePayTab.GetListInfo("FeeBGTruePayTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return;
            }



            DGBY.Model.FeeBGTruePayTab modelFeeBGTruePayTab = new DGBY.Model.FeeBGTruePayTab();

            modelFeeBGTruePayTab.PaidanRegisterTabID = nPaidanRegisterTabID;
            modelFeeBGTruePayTab.ToPubBianHao = "";
            modelFeeBGTruePayTab.ToPrivateBianHao = "";
            modelFeeBGTruePayTab.SBDate = DateTime.Parse("1900-01-01");
            //modelFeeBGTruePayTab.TruePayDate = DateTime.Parse("1900-01-01");
            //modelFeeBGTruePayTab.InputDate = DateTime.Parse("1900-01-01"); 
            modelFeeBGTruePayTab.TruePayMonth = 0;
            modelFeeBGTruePayTab.ShouldPayMonth = 0;
            modelFeeBGTruePayTab.PrivateTruePayMoney = 0;
            modelFeeBGTruePayTab.PubTruePayMoney = 0;

            modelFeeBGTruePayTab.ToPubFormula = "";
            modelFeeBGTruePayTab.ToPrivateFormula = "";

            modelFeeBGTruePayTab.JinBanPerson = "";
            modelFeeBGTruePayTab.RecvMonyePerson = "";

            modelFeeBGTruePayTab.IsToRecvPayTab = 0;
            modelFeeBGTruePayTab.IsToFinCheckMoneyTab = 0;
            modelFeeBGTruePayTab.Note = "";

            modelFeeBGTruePayTab.bitFiledReserv1 = false;
            modelFeeBGTruePayTab.bitFiledReserv2 = false;

            modelFeeBGTruePayTab.stringFiledReserv1 = "";
            modelFeeBGTruePayTab.stringFiledReserv2 = "";
            modelFeeBGTruePayTab.stringFiledReserv3 = "";
            modelFeeBGTruePayTab.stringFiledReserv4 = "";

            modelFeeBGTruePayTab.intFiledReserv1 = 33;
            modelFeeBGTruePayTab.intFiledReserv2 = 10;
            modelFeeBGTruePayTab.intFiledReserv3 = 0;
            modelFeeBGTruePayTab.intFiledReserv4 = 0;
            modelFeeBGTruePayTab.datetimeFiledReserv1 = System.DateTime.Now.Date;
            modelFeeBGTruePayTab.datetimeFiledReserv2 = System.DateTime.Now.Date;

            modelFeeBGTruePayTab.decimalFiledReserv1 = 0;
            modelFeeBGTruePayTab.decimalFiledReserv2 = 0;
            modelFeeBGTruePayTab.decimalFiledReserv3 = 0;
            modelFeeBGTruePayTab.decimalFiledReserv4 = 0;
            // modelFeeBGTruePayTab.SjDate = System.DateTime.Now.Date;
            m_bllFeeBGTruePayTab.TransAdd(modelFeeBGTruePayTab, m_SQLStringList, m_arrayList);

        }
                   

        private void UpdateGuiCounByPaidanID(int nPaidanID)
        {
            m_bllSJCKHTTab.UpdateGuiCounByPaidanID(nPaidanID);
            DataSet ds = m_bllSJCKHTTab.GetList("PaidanRegisterTabID = '" + nPaidanID.ToString() + "'");
            int nCount = (int)ds.Tables[0].Rows[0]["SJGuiCount"];
            if(nCount > 0)
            {
                DGBY.Model.FeeSJTruePayTab modelSJTruePayTabOld = m_bllFeeSJTruePayTab.GetModelByPaidanID(nPaidanID);
                modelSJTruePayTabOld.ShouldRecvMoney = 20;
                m_bllFeeSJTruePayTab.Update(modelSJTruePayTabOld);
            }

        }

        private void buttonAddFillBoxSheet_Click(object sender, EventArgs e)
        {
            if (CheckSBDate())
            {
                MessageBox.Show("综合登记表该合同号已经登记申报日期，不能修改单据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            try
            {
                int nPaidanID = Convert.ToInt32(this.comboBoxContractNo.SelectedValue.ToString(), 10);
                if (Frm_Main.m_nEmptyDanID == nPaidanID)
                {
                    MessageBox.Show("合同号不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                m_SQLStringList.Clear();
                m_arrayList.Clear();
                //DataSet ds = m_bllSJPackingTab.ShowOneSJPackRec("ContractCode = '" + this.comboBoxContractNo.Text + "'");

                //if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                //{
                //    MessageBox.Show("该合同编号已有对应的商检_装箱单了!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //    return;
                //}
                DGBY.Model.SJPackingTab modelSJPackingTab = new DGBY.Model.SJPackingTab();

                modelSJPackingTab.Note = this.textBoxNote.Text;
                modelSJPackingTab.ShoeBrand = this.textBoxMark.Text;
                modelSJPackingTab.ShipMarks = this.textBoxMaiTou.Text;

                modelSJPackingTab.IsShoePack = this.checkBoxIsShoe.Checked ? "是" : "否";
                modelSJPackingTab.SJPackDJDate = System.DateTime.Now.Date;

                modelSJPackingTab.SJPackDJNo = MakeSJPackDJNo();

                if (this.comboBoxCoinUnit2.SelectedValue != null)
                    modelSJPackingTab.BiZhiTabID = Convert.ToInt32(this.comboBoxCoinUnit2.SelectedValue.ToString(), 10);
                if (this.comboBoxRecvGoodsComp.SelectedValue != null)
                    modelSJPackingTab.SHCompTabID = Convert.ToInt32(this.comboBoxRecvGoodsComp.SelectedValue.ToString(), 10);
                if (this.comboBoxStartCountry.SelectedValue != null)
                    modelSJPackingTab.QYCountryTabID = Convert.ToInt32(this.comboBoxStartCountry.SelectedValue.ToString(), 10);
                if (this.comboBoxPort.SelectedValue != null)
                    modelSJPackingTab.ZYHarborTabID = Convert.ToInt32(this.comboBoxPort.SelectedValue.ToString(), 10);
                if (this.comboBoxOutSideCate.SelectedValue != null)
                    modelSJPackingTab.BZSortTabID = Convert.ToInt32(this.comboBoxOutSideCate.SelectedValue.ToString(), 10);
                if (this.comboBoxContractNo.SelectedValue != null)
                    modelSJPackingTab.PaidanRegisterTabID = Convert.ToInt32(this.comboBoxContractNo.SelectedValue.ToString(), 10);

                m_bllSJPackingTab.TransAdd(modelSJPackingTab,m_SQLStringList, m_arrayList);

                int nYSMethodTabID = 10;
                AddOtherSheetRec(modelSJPackingTab.PaidanRegisterTabID, false, ref nYSMethodTabID);

                //CommerCheckFillBoxEventArgs addEventArgs = new CommerCheckFillBoxEventArgs();
                ////通知所有事件订阅者  
                //addEventArgs.m_nPaidanID = modelSJPackingTab.PaidanRegisterTabID;
                //addEventArgs.m_arrayList = m_arrayList;
                //addEventArgs.m_SQLStringList = m_SQLStringList;
                //this.OnAdd(addEventArgs);

                AddBGPackingRecAfterTrans(modelSJPackingTab.PaidanRegisterTabID, modelSJPackingTab.SJPackDJNo);
                AddTYInvoiceTabRecAfterTrans(modelSJPackingTab.PaidanRegisterTabID, nYSMethodTabID);
                AddFinInvoiceRecordTabNewAfterTrans(modelSJPackingTab.PaidanRegisterTabID);
                AddFinCheckInvoiceRecordDetailTabNewAfterTrans(modelSJPackingTab.PaidanRegisterTabID);
                AddFacFeeTab(modelSJPackingTab.PaidanRegisterTabID);
                AddFeeSJTruePayTab(modelSJPackingTab.PaidanRegisterTabID);
                AddFeeBGTruePayTab(modelSJPackingTab.PaidanRegisterTabID);
                AddFeeDLCWTruePayTab(modelSJPackingTab.PaidanRegisterTabID);
                AddFeeHKCWTruePayTab(modelSJPackingTab.PaidanRegisterTabID);
                AddFeeHKYSTruePayTab(modelSJPackingTab.PaidanRegisterTabID);
                AddFeeDHLTruePayTab(modelSJPackingTab.PaidanRegisterTabID);
                //AddFeeZXZTruePayTab(modelSJPackingTab.PaidanRegisterTabID);
                //AddFeeJCFTruePayTab(modelSJPackingTab.PaidanRegisterTabID);
                AddFeeDZTruePayTab(modelSJPackingTab.PaidanRegisterTabID);
                m_bllSJPackingTab.ExecuteSqlTran(m_SQLStringList, m_arrayList);

                //更新商检柜数
                UpdateGuiCounByPaidanID(modelSJPackingTab.PaidanRegisterTabID);
                Frm_Main.Log2DB(this.Text, "增加单据", modelSJPackingTab.SJPackDJNo.ToString());
                ShowAllRecordInDataGridView("PaidanRegisterTab.ContractCode = '" + this.comboBoxContractNo.Text + "'");

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
          
        }

        private void buttonModifyFillBoxSheet_Click(object sender, EventArgs e)
        {
            if (CheckSBDate())
            {
                MessageBox.Show("综合登记表该合同号已经登记申报日期，不能修改单据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            try
            {
                m_SQLStringList.Clear();
                m_arrayList.Clear();
                DGBY.Model.SJPackingTab modelSJPackingTabOld = m_bllSJPackingTab.GetModel(m_nSelectSJPackingTabID);
                if (modelSJPackingTabOld == null)
                {
                    MessageBox.Show("数据库不存在该记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                DataSet ds = m_bllSJPackingTab.ShowOneSJPackRec("SJPackingTab.PaidanRegisterTabID = '" + modelSJPackingTabOld.PaidanRegisterTabID + "'");
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        int nPackingId = Convert.ToInt32(ds.Tables[0].Rows[i]["SJPackingTabID"].ToString(), 10);
                        DGBY.Model.SJPackingTab modelSJPackingTab = m_bllSJPackingTab.GetModel(nPackingId);
                        if (nPackingId == m_nSelectSJPackingTabID)
                        {
                            modelSJPackingTab.Note = this.textBoxNote.Text;
                            modelSJPackingTab.ShoeBrand = this.textBoxMark.Text;
                            modelSJPackingTab.ShipMarks = this.textBoxMaiTou.Text;
                            modelSJPackingTab.IsShoePack = this.checkBoxIsShoe.Checked ? "是" : "否";
                        }
                        //   if (this.comboBoxContractNo.SelectedValue != null)
                        if (modelSJPackingTab.PaidanRegisterTabID != modelSJPackingTabOld.PaidanRegisterTabID)
                        {
                            MessageBox.Show("商检装箱单出现未知错误，请速联系软件作者宋波!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        //modelSJPackingTab.SJPackDJDate = System.DateTime.Now.Date;
                        //modelSJPackingTab.SJPackDJNo = modelSJPackingTabOld.SJPackDJNo;
                        if (this.comboBoxCoinUnit2.SelectedValue != null)
                            modelSJPackingTab.BiZhiTabID = Convert.ToInt32(this.comboBoxCoinUnit2.SelectedValue.ToString(), 10);
                        if (this.comboBoxRecvGoodsComp.SelectedValue != null)
                            modelSJPackingTab.SHCompTabID = Convert.ToInt32(this.comboBoxRecvGoodsComp.SelectedValue.ToString(), 10);
                        if (this.comboBoxStartCountry.SelectedValue != null)
                            modelSJPackingTab.QYCountryTabID = Convert.ToInt32(this.comboBoxStartCountry.SelectedValue.ToString(), 10);
                        if (this.comboBoxPort.SelectedValue != null)
                            modelSJPackingTab.ZYHarborTabID = Convert.ToInt32(this.comboBoxPort.SelectedValue.ToString(), 10);
                        if (this.comboBoxOutSideCate.SelectedValue != null)
                            modelSJPackingTab.BZSortTabID = Convert.ToInt32(this.comboBoxOutSideCate.SelectedValue.ToString(), 10);


                        m_bllSJPackingTab.TransUpdate(modelSJPackingTab, m_SQLStringList, m_arrayList, i);
                    }
                }


                ModifySjGHContractRecHuilv(modelSJPackingTabOld.PaidanRegisterTabID);
                //修改报关装箱单
                ds = m_bllBGPackingTab.GetList("BGSJPackDJNo = '" + modelSJPackingTabOld.SJPackDJNo + "'");
                int nBGPackingTabID = 0;
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    nBGPackingTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["BGPackingTabID"].ToString(), 10);
                }
                
                ds = m_bllBGPackingTab.GetList("BGPackingTab.PaidanRegisterTabID = '" + modelSJPackingTabOld.PaidanRegisterTabID + "'");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        int nBGPackingTabIDTemp = Convert.ToInt32(ds.Tables[0].Rows[i]["BGPackingTabID"].ToString(), 10);
                        DGBY.Model.BGPackingTab modelBGPackingTab = m_bllBGPackingTab.GetModel(nBGPackingTabIDTemp);

                        if (nBGPackingTabID == nBGPackingTabIDTemp)
                        {
                            modelBGPackingTab.Note = this.textBoxNote.Text;
                            modelBGPackingTab.ShoeBrand = this.textBoxMark.Text;
                            modelBGPackingTab.ShipMarks = this.textBoxMaiTou.Text;
                            modelBGPackingTab.IsShoePack = this.checkBoxIsShoe.Checked ? "是" : "否";

                            modelBGPackingTab.SJPackingTabID = m_nSelectSJPackingTabID;
                        }

                        if (this.comboBoxCoinUnit2.SelectedValue != null)
                            modelBGPackingTab.BiZhiTabID = Convert.ToInt32(this.comboBoxCoinUnit2.SelectedValue.ToString(), 10);
                        if (this.comboBoxRecvGoodsComp.SelectedValue != null)
                            modelBGPackingTab.SHCompTabID = Convert.ToInt32(this.comboBoxRecvGoodsComp.SelectedValue.ToString(), 10);
                        if (this.comboBoxStartCountry.SelectedValue != null)
                            modelBGPackingTab.QYCountryTabID = Convert.ToInt32(this.comboBoxStartCountry.SelectedValue.ToString(), 10);
                        if (this.comboBoxPort.SelectedValue != null)
                            modelBGPackingTab.ZYHarborTabID = Convert.ToInt32(this.comboBoxPort.SelectedValue.ToString(), 10);
                        if (this.comboBoxOutSideCate.SelectedValue != null)
                            modelBGPackingTab.BZSortTabID = Convert.ToInt32(this.comboBoxOutSideCate.SelectedValue.ToString(), 10);
                        //if (this.comboBoxContractNo.SelectedValue != null)
                        //    modelBGPackingTab.PaidanRegisterTabID = Convert.ToInt32(this.comboBoxContractNo.SelectedValue.ToString(), 10);
                        modelBGPackingTab.BGHarborTabID = 1;
                        m_bllBGPackingTab.TransUpdate(modelBGPackingTab, m_SQLStringList, m_arrayList, i);

                    }
                }
                m_bllSJPackingTab.ExecuteSqlTran(m_SQLStringList, m_arrayList);
                Frm_Main.Log2DB(this.Text, "修改单据", modelSJPackingTabOld.SJPackDJNo.ToString());
                ShowFillBoxSheetByContractCode(this.comboBoxContractNo.Text);
                MessageBox.Show("数据修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        
        }

        private void buttonDelFillBoxSheet_Click(object sender, EventArgs e)
        {
            if (CheckSBDate())
            {
                MessageBox.Show("综合登记表该合同号已经登记申报日期，不能修改单据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            m_SQLStringList.Clear();
            m_arrayList.Clear();
            DGBY.Model.SJPackingTab modelSJPackingTabOld = m_bllSJPackingTab.GetModel(m_nSelectSJPackingTabID);

            if (modelSJPackingTabOld == null)
            {
                MessageBox.Show("数据库不存在该记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            DGBY.Model.PaidanRegisterTab modelPaidanRegisterTabOld = m_bllPaidanRegisterTab.GetModel(modelSJPackingTabOld.PaidanRegisterTabID);
 

            if (Frm_Main.m_nLoginUserId != modelPaidanRegisterTabOld.UserPasswordTabID)
            {
                MessageBox.Show("该合同号不是你派的单，不能删除!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }



            if (MessageBox.Show("确实要删除该条记录!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
            {
                m_bllSJPackingTab.TransDelete(m_nSelectSJPackingTabID, m_SQLStringList, m_arrayList);

                //删除相应的报关装箱单
                DataSet ds = m_bllBGPackingTab.GetList("BGSJPackDJNo = '" + modelSJPackingTabOld.SJPackDJNo + "'");
                int nBGPackingTabID = 0;
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    nBGPackingTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["BGPackingTabID"].ToString(), 10);
                    int nTempPaidanRegisterTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["PaidanRegisterTabID"].ToString(), 10);
                    if (nTempPaidanRegisterTabID != modelSJPackingTabOld.PaidanRegisterTabID)
                    {
                        MessageBox.Show("商检装箱单和报关装箱单合同ID不同，不能删除!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    m_bllBGPackingTab.TransDelete(nBGPackingTabID, m_SQLStringList, m_arrayList);
                }

                m_bllSJPackingTab.ExecuteSqlTran(m_SQLStringList, m_arrayList);

                DGBY.Model.LogRecTab modelLogRecTab = new DGBY.Model.LogRecTab();
                modelLogRecTab.LogDate = System.DateTime.Now.Date;
                modelLogRecTab.LogContent = Frm_Main.m_strLoginUser + "删除了合同号"
                    + modelPaidanRegisterTabOld.ContractCode + "的商检装箱单";
                m_bllLogRecTab.Add(modelLogRecTab);

                //更新商检柜数
                UpdateGuiCounByPaidanID(modelSJPackingTabOld.PaidanRegisterTabID);
                Frm_Main.Log2DB(this.Text, "删除单据", modelSJPackingTabOld.SJPackDJNo.ToString());

                ShowAllRecordInDataGridView("PaidanRegisterTab.ContractCode = '" + this.comboBoxContractNo.Text + "'");
                MessageBox.Show("数据删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.textBoxNote.Text = "";
                this.textBoxSecondSheetNo.Text = "";
                this.textBoxMark.Text = "";
                this.textBoxMaiTou.Text = "";
                return;
            }
        }



        private void checkBoxIsShoe_CheckedChanged(object sender, EventArgs e)
        {
            this.textBoxMark.ReadOnly = !this.checkBoxIsShoe.Checked;
            if (!this.checkBoxIsShoe.Checked)
                this.textBoxMark.Text = "";
        }

        /*
        private void CopySJPackTab(int nPaidanRegisterTabID, long nOldSjDjNo, long nNewSjDjNo, int nNewSJPackTabID)
        {
            DataSet ds = m_bllSJPackingTab.ShowOneSJPackRec("SJPackDJNo = '" + nOldSjDjNo.ToString() + "'");
            DateTime dt = System.DateTime.Now.Date;
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                int nSJPackingTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["SJPackingTabID"].ToString(), 10);
                DGBY.Model.SJPackingTab modelSJPackingTabOld = m_bllSJPackingTab.GetModel(nSJPackingTabID);
                DGBY.Model.SJPackingTab modelSJPackingTab = new DGBY.Model.SJPackingTab();
                modelSJPackingTab.SJPackingTabID = nNewSJPackTabID;
                modelSJPackingTab.Note = modelSJPackingTabOld.Note;
                modelSJPackingTab.ShoeBrand = modelSJPackingTabOld.ShoeBrand;
                modelSJPackingTab.ShipMarks = modelSJPackingTabOld.ShipMarks;

                modelSJPackingTab.IsShoePack = modelSJPackingTabOld.IsShoePack;
                modelSJPackingTab.SJPackDJDate = dt.Date;

                modelSJPackingTab.SJPackDJNo = nNewSjDjNo;


                modelSJPackingTab.BiZhiTabID = modelSJPackingTabOld.BiZhiTabID;

                modelSJPackingTab.SHCompTabID = modelSJPackingTabOld.SHCompTabID;

                modelSJPackingTab.QYCountryTabID = modelSJPackingTabOld.QYCountryTabID;

                modelSJPackingTab.ZYHarborTabID = modelSJPackingTabOld.BZSortTabID;

                modelSJPackingTab.BZSortTabID = modelSJPackingTabOld.BZSortTabID;

                modelSJPackingTab.PaidanRegisterTabID = nPaidanRegisterTabID;

                m_bllSJPackingTab.TransAddEx(modelSJPackingTab, m_SQLStringList, m_arrayList);
            }
        }
        */

        private int CopySJPackTab(int nPaidanRegisterTabID, long nOldSjDjNo, long nNewSjDjNo)
        {
            DataSet ds = m_bllSJPackingTab.ShowOneSJPackRec("SJPackDJNo = '" + nOldSjDjNo.ToString() + "'");
            DateTime dt = System.DateTime.Now.Date;
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                int nSJPackingTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["SJPackingTabID"].ToString(), 10);
                DGBY.Model.SJPackingTab modelSJPackingTabOld = m_bllSJPackingTab.GetModel(nSJPackingTabID);
                DGBY.Model.SJPackingTab modelSJPackingTab = new DGBY.Model.SJPackingTab();
                modelSJPackingTab.Note = modelSJPackingTabOld.Note;
                modelSJPackingTab.ShoeBrand = modelSJPackingTabOld.ShoeBrand;
                modelSJPackingTab.ShipMarks = modelSJPackingTabOld.ShipMarks;

                modelSJPackingTab.IsShoePack = modelSJPackingTabOld.IsShoePack;
                modelSJPackingTab.SJPackDJDate = dt.Date;

                modelSJPackingTab.SJPackDJNo = nNewSjDjNo;


                modelSJPackingTab.BiZhiTabID = modelSJPackingTabOld.BiZhiTabID;

                modelSJPackingTab.SHCompTabID = modelSJPackingTabOld.SHCompTabID;

                modelSJPackingTab.QYCountryTabID = modelSJPackingTabOld.QYCountryTabID;

                modelSJPackingTab.ZYHarborTabID = modelSJPackingTabOld.BZSortTabID;

                modelSJPackingTab.BZSortTabID = modelSJPackingTabOld.BZSortTabID;

                modelSJPackingTab.PaidanRegisterTabID = nPaidanRegisterTabID;

                return m_bllSJPackingTab.Add(modelSJPackingTab);
            }

            return -1;
        }

        private void buttonCopySheet_Click(object sender, EventArgs e)
        {
            try
            {
                if (CheckSBDate())
                {
                    MessageBox.Show("综合登记表该合同号已经登记申报日期，不能修改单据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                m_SQLStringList.Clear();
                m_arrayList.Clear();

                DataSet ds = m_bllSJPackingTab.ShowOneSJPackRec("SJPackDJNo = '" + this.textBoxSecondSheetNo.Text + "'");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    string strContractNo = ds.Tables[0].Rows[0]["合同编号"].ToString();
                    DataSet dsContract = m_bllSJCKHTTab.GetAllSJPackingID(strContractNo);
                    bool bIsDisCount = (bool)dsContract.Tables[0].Rows[0]["isDisCount"];
                    int nPaidanRegisterTabID = 0;

                    Int64 n64NewDJNo = MakeSJPackDJNo();
                    DataSet dsTemp = m_bllPaidanRegisterTab.GetAllPaiDanList("ContractCode = '" + this.comboBoxContractNo.Text + "'");
                    if (dsTemp.Tables.Count > 0 && dsTemp.Tables[0].Rows.Count > 0)
                    {
                        int nIDTest = Convert.ToInt32(this.comboBoxContractNo.SelectedValue.ToString(), 10);
                        nPaidanRegisterTabID = Convert.ToInt32(dsTemp.Tables[0].Rows[0]["PaidanRegisterTabID"].ToString(), 10);

                        if (Frm_Main.m_nEmptyDanID == nPaidanRegisterTabID)
                        {
                            MessageBox.Show("合同号不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        //m_bllSJPackingTab.CopyDJNo(nPaidanRegisterTabID, dt, n64NewDJNo
                        //    , Convert.ToInt64(this.textBoxSecondSheetNo.Text, 10), m_SQLStringList, m_arrayList);
                        int nNewSJPackTabID = CopySJPackTab(nPaidanRegisterTabID, Convert.ToInt64(this.textBoxSecondSheetNo.Text, 10), n64NewDJNo);
                        if (nNewSJPackTabID <= 0)
                            return;

                        DGBY.Model.SJPackingTab modelSJPackingTabNew = m_bllSJPackingTab.GetModel(nNewSJPackTabID);
                        this.comboBoxCoinUnit2.SelectedValue = modelSJPackingTabNew.BiZhiTabID;

                        int nYSMethodTabID = 10;
                        AddOtherSheetRec(nPaidanRegisterTabID, bIsDisCount, ref nYSMethodTabID);
                        int nNewBGPackTabID = AddBGPackingRec(nPaidanRegisterTabID, n64NewDJNo, modelSJPackingTabNew);
                        AddTYInvoiceTabRecAfterTrans(nPaidanRegisterTabID, nYSMethodTabID);
                        AddFinInvoiceRecordTabNewAfterTrans(nPaidanRegisterTabID);
                        AddFinCheckInvoiceRecordDetailTabNewAfterTrans(nPaidanRegisterTabID);
                        AddFacFeeTab(nPaidanRegisterTabID);
                        AddFeeSJTruePayTab(nPaidanRegisterTabID);
                        AddFeeBGTruePayTab(nPaidanRegisterTabID);
                        AddFeeDLCWTruePayTab(nPaidanRegisterTabID);
                        AddFeeHKCWTruePayTab(nPaidanRegisterTabID);
                        AddFeeHKYSTruePayTab(nPaidanRegisterTabID);
                        AddFeeDHLTruePayTab(nPaidanRegisterTabID);
                        //AddFeeZXZTruePayTab(nPaidanRegisterTabID);
                        //AddFeeJCFTruePayTab(nPaidanRegisterTabID);
                        AddFeeDZTruePayTab(nPaidanRegisterTabID);
                        m_bllSJPackingTab.CopyDJNoForMXGoods(nNewSJPackTabID, Convert.ToInt64(this.textBoxSecondSheetNo.Text, 10));

                        //生成相应的报关装箱单明细
                        Decimal dtBackTaxPoint = 0;
                        DataSet dsInfo = m_bllFactoryGoodsTab.GetGoodsBandInfo("PaidanRegisterTab.PaidanRegisterTabID = '"
                            + nPaidanRegisterTabID.ToString() + "'");
                        if (dsInfo.Tables.Count > 0 && dsInfo.Tables[0].Rows.Count > 0)
                        {
                            dtBackTaxPoint = Convert.ToDecimal(dsInfo.Tables[0].Rows[0]["退税点"].ToString());
                        }

                        Decimal dtFactorA = 0;
                        dsInfo = m_bllFactoryDataTab.GetFactorAInfo("PaidanRegisterTab.PaidanRegisterTabID = '"
                            + nPaidanRegisterTabID.ToString() + "'");
                        if (dsInfo.Tables.Count > 0 && dsInfo.Tables[0].Rows.Count > 0)
                        {
                            dtFactorA = Convert.ToDecimal(dsInfo.Tables[0].Rows[0]["系数A"].ToString());
                        }

                        int nSelectSJPackingTabID = 0;

                        DataSet dsTemp2 = m_bllSJPackingTab.ShowOneSJPackRec("SJPackingTab.SJPackDJNo = '" + this.textBoxSecondSheetNo.Text + "'");
                        if (dsTemp2.Tables.Count > 0 && dsTemp2.Tables[0].Rows.Count > 0)
                        {
                            nSelectSJPackingTabID = Convert.ToInt32(dsTemp2.Tables[0].Rows[0]["SJPackingTabID"].ToString(), 10);
                            // ds = m_bllBGPackingTab.GetList("BGSJPackDJNo = '" + n64NewDJNo + "'");
                            DataSet m_ds = m_bllSJPackGoodsMXTab.GetListByConditionAnother("SJPackGoodsMXTab.SJPackingTabID = '" + nSelectSJPackingTabID + "'");
                            if (m_ds.Tables.Count > 0 && m_ds.Tables[0].Rows.Count > 0)
                            {
                                for (int i = 0; i < m_ds.Tables[0].Rows.Count; i++)
                                {
                                    DGBY.Model.BGPackGoodsMXTab modelBGPackGoodsMXTab = new DGBY.Model.BGPackGoodsMXTab();

                                    modelBGPackGoodsMXTab.GoodsMXName = m_ds.Tables[0].Rows[i]["商品名称"].ToString();
                                    modelBGPackGoodsMXTab.GGXHZDEtc = m_ds.Tables[0].Rows[i]["质地"].ToString();
                                    modelBGPackGoodsMXTab.GGXHZDEtc2 = m_ds.Tables[0].Rows[i]["规格型号"].ToString();
                                    modelBGPackGoodsMXTab.FPieceNum = Convert.ToInt32(m_ds.Tables[0].Rows[i]["件数"].ToString(), 10);
                                    modelBGPackGoodsMXTab.FNumber = Convert.ToDecimal(m_ds.Tables[0].Rows[i]["数量"].ToString());
                                    modelBGPackGoodsMXTab.FMaoWeight = Convert.ToDecimal(m_ds.Tables[0].Rows[i]["毛重"].ToString());
                                    modelBGPackGoodsMXTab.FFactWeight = Convert.ToDecimal(m_ds.Tables[0].Rows[i]["净重"].ToString());
                                    modelBGPackGoodsMXTab.CKHTDCost = Convert.ToDecimal(m_ds.Tables[0].Rows[i]["单价"].ToString());
                                    modelBGPackGoodsMXTab.CKHTJinE = Convert.ToDecimal(m_ds.Tables[0].Rows[i]["金额"].ToString());
                                    modelBGPackGoodsMXTab.HMaoWeight = Convert.ToDecimal(m_ds.Tables[0].Rows[i]["打折单价"].ToString());
                                    modelBGPackGoodsMXTab.HZMaoWeight = Convert.ToDecimal(m_ds.Tables[0].Rows[i]["打折金额"].ToString());
                                    modelBGPackGoodsMXTab.BGPackingTabID = nNewBGPackTabID;
                                    modelBGPackGoodsMXTab.BGSeqNo = Convert.ToInt32(m_ds.Tables[0].Rows[i]["序号"].ToString(), 10);
                                    modelBGPackGoodsMXTab.BackTaxPoint = dtBackTaxPoint;
                                    modelBGPackGoodsMXTab.FactorA = dtFactorA;
                                    //   modelBGPackGoodsMXTab.BiZhiTabID = Convert.ToInt32(m_ds.Tables[0].Rows[i]["币制"].ToString(), 10);

                                    modelBGPackGoodsMXTab.NumDanWeiTabID = Convert.ToInt32(m_ds.Tables[0].Rows[i]["单位"].ToString(), 10);
                                    //这里实在无法使用事务，因为此时的BGPackingTabID还没有生成
                                    m_bllBGPackGoodsMXTab.TransAdd(modelBGPackGoodsMXTab, m_SQLStringList, m_arrayList, i);
                                }
                            }
                        }

                        m_bllSJPackingTab.ExecuteSqlTran(m_SQLStringList, m_arrayList);

                        //更新商检柜数
                        UpdateGuiCounByPaidanID(nPaidanRegisterTabID);
                        Frm_Main.Log2DB(this.Text, "复制单据", this.textBoxSecondSheetNo.Text.ToString());
                        ShowFillBoxSheetByContractCode(this.comboBoxContractNo.Text);
                        LoggingHelper.Writelog("商检装箱单复制单据，单据号：" + this.textBoxSecondSheetNo.Text); 
                    }
                }
                else
                {
                    MessageBox.Show("该单据号没有对应的商检_装箱单记录，因此无法复制单据，请重新输入单据号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }    
        }

        private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
        {
            ClassUltraGridCommonSet.ultraGrid1_InitializeRowFilter(e);
            ClassUltraGridCommonSet.InitUltraWinGridRowNumSetting(e);

            InitColumnWidth1();
        }

        private void ultraGrid1_AfterCellActivate(object sender, EventArgs e)
        {
            int iIndex = this.ultraGrid1.ActiveCell.Row.Index;
            if (iIndex < 0)
                return;


            string strSJPackingTabID = this.ultraGrid1.Rows[this.ultraGrid1.ActiveCell.Row.Index].Cells[0].Text;
            m_nSelectSJPackingTabID = Convert.ToInt32(strSJPackingTabID, 10);
            cellSJPackingTabClick();
            this.ultraGrid2.Text = "商检装箱单明细(单据编号：" + this.textBoxFirstSheetNo.Text + ")";
        }

        private void ShowAllMXRecordInDataGridView(int nSJPackingTabID)
        {

            DataSet m_ds = m_bllSJPackGoodsMXTab.GetListByConditionAnother2("SJPackGoodsMXTab.SJPackingTabID = '" + nSJPackingTabID + "'");
            ultraGrid2.DataSource = null;

            if (m_ds.Tables.Count > 0 && m_ds.Tables[0].Rows.Count > 0)
            {
                //int nPieceTotal = 0;
                //Decimal nNumTotal = 0;
                //Decimal dtMaoWeight = 0;
                //Decimal dtJingWeight = 0;
                //Decimal dtJinE = 0;
                //for (int i = 0; i < m_ds.Tables[0].Rows.Count; i++)
                //{
                //    nPieceTotal += Convert.ToInt32(m_ds.Tables[0].Rows[i]["件数"].ToString(), 10);
                //    nNumTotal += Convert.ToDecimal(m_ds.Tables[0].Rows[i]["数量"].ToString());
                //    dtMaoWeight += Convert.ToDecimal(m_ds.Tables[0].Rows[i]["毛重"].ToString());
                //    dtJingWeight += Convert.ToDecimal(m_ds.Tables[0].Rows[i]["净重"].ToString());
                //    dtJinE += Convert.ToDecimal(m_ds.Tables[0].Rows[i]["金额"].ToString());
                //}

                //DataRow dr = m_ds.Tables[0].NewRow();
                //dr["件数"] = nPieceTotal;
                //dr["数量"] = nNumTotal;
                //dr["毛重"] = dtMaoWeight;
                //dr["净重"] = dtJingWeight;
                //dr["金额"] = dtJinE;
                //dr["商品名称"] = "合计";
                //m_ds.Tables[0].Rows.Add(dr.ItemArray);


            }
            DataSet ds = m_bllNumDanWeiTab.GetList("");

            this.ultraDropDown1.DataSource = ds.Tables[0];
            this.ultraDropDown1.DisplayMember = "单位名称";
            this.ultraDropDown1.ValueMember = "NumDanWeiTabID";
            this.ultraDropDown1.DisplayLayout.Bands[0].Columns[0].Hidden = true;

            ultraGrid2.DataSource = m_ds.Tables[0];
            ultraGrid2.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            ultraGrid2.DisplayLayout.Bands[0].Columns[1].Hidden = true;
            ultraGrid2.DisplayLayout.Bands[0].Columns["单价"].Hidden = true;
            ultraGrid2.DisplayLayout.Bands[0].Columns["金额"].Hidden = true;
            ultraGrid2.DisplayLayout.Bands[0].Columns["打折单价"].Hidden = true;
            ultraGrid2.DisplayLayout.Bands[0].Columns["打折金额"].Hidden = true;
            this.ultraGrid2.DisplayLayout.Bands[0].Columns["单位"].ValueList = this.ultraDropDown1;
        }

        private void InitNewAddRowValue(int nIndex)
        {
          
            UltraGridRow CurrentUGR = ultraGrid2.Rows[nIndex];

            CurrentUGR.Cells["商品名称"].Value = "";
            CurrentUGR.Cells["质地"].Value = "";
            CurrentUGR.Cells["规格型号"].Value = "";
            CurrentUGR.Cells["件数"].Value = 0;
            CurrentUGR.Cells["数量"].Value = 0;
            CurrentUGR.Cells["毛重"].Value = 0;
            CurrentUGR.Cells["净重"].Value = 0;
            CurrentUGR.Cells["单位"].Value = 1;
  
        }
        private bool AddGoodsDetail(int nRowIndex)
        {
            
            try
            {
                m_SQLStringList.Clear();
                m_arrayList.Clear();
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid2.Rows[nRowIndex];

                DGBY.Model.SJPackGoodsMXTab modelSJPackGoodsMXTab = new DGBY.Model.SJPackGoodsMXTab();

                modelSJPackGoodsMXTab.GoodsMXName = CurrentUGR.Cells["商品名称"].Value.ToString() ;
                modelSJPackGoodsMXTab.GGXHZDEtc = CurrentUGR.Cells["质地"].Value.ToString();
                modelSJPackGoodsMXTab.GGXHZDEtc2 = CurrentUGR.Cells["规格型号"].Value.ToString();
                modelSJPackGoodsMXTab.PieceNum = Convert.ToInt32(CurrentUGR.Cells["件数"].Value.ToString(), 10);
                modelSJPackGoodsMXTab.Number = Convert.ToDecimal(CurrentUGR.Cells["数量"].Value.ToString());
                modelSJPackGoodsMXTab.MaoWeight = Convert.ToDecimal(CurrentUGR.Cells["毛重"].Value.ToString());
                modelSJPackGoodsMXTab.FactWeight = Convert.ToDecimal(CurrentUGR.Cells["净重"].Value.ToString());

                modelSJPackGoodsMXTab.NumDanWeiTabID = Convert.ToInt32(CurrentUGR.Cells["单位"].Value.ToString(), 10);
                //modelSJPackGoodsMXTab.SJSeqNo = (int)CurrentUGR.Cells["序号"].Value;
                modelSJPackGoodsMXTab.CKHTDCost = 0;
                modelSJPackGoodsMXTab.CKHTJinE = 0;
           
                DataSet ds = m_bllSJPackingTab.ShowOneSJPackRec("SJPackingTab.SJPackDJNo = '" + this.textBoxFirstSheetNo.Text + "'");
                int nSJPackingTabID = 0;
                Int64 n64NewDJNo = 0;
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    string strSJPackingTabIDNo = ds.Tables[0].Rows[0]["SJPackingTabID"].ToString();
                    n64NewDJNo = (Int64)ds.Tables[0].Rows[0]["单据编号"];
                    nSJPackingTabID = Convert.ToInt32(strSJPackingTabIDNo, 10);
                    modelSJPackGoodsMXTab.SJPackingTabID = nSJPackingTabID;
                }
                else
                {
                    MessageBox.Show("商检_装箱单概况表为空，所以无法增加货物明细!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                
                if (CurrentUGR.Cells["序号"].Value.ToString() == "")
                {
                    ds = m_bllSJPackGoodsMXTab.GetSJPackMXMaxSeqNo(nSJPackingTabID);
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        string strSJPackingTabIDNo = ds.Tables[0].Rows[0]["MaxJPackDJNum"].ToString();
                        if (strSJPackingTabIDNo.CompareTo("") == 0)
                            modelSJPackGoodsMXTab.SJSeqNo = 1;
                        else
                        {
                            int nSeqNo = Convert.ToInt32(strSJPackingTabIDNo, 10);
                            modelSJPackGoodsMXTab.SJSeqNo = nSeqNo + 1;
                        }

                    }
                }
                else
                {
                    int nInputSeqNo = Convert.ToInt32(CurrentUGR.Cells["序号"].Value.ToString(), 10);
                    modelSJPackGoodsMXTab.SJSeqNo = nInputSeqNo;
                }
   

                bool bSeqNoExist = false;
                ds = m_bllSJPackGoodsMXTab.GetListByCondition("SJPackGoodsMXTab.SJSeqNo = '" + modelSJPackGoodsMXTab.SJSeqNo + "' and SJPackGoodsMXTab.SJPackingTabID = '" + nSJPackingTabID.ToString() + "'");
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    m_bllSJPackGoodsMXTab.MoveRecordAfterSeqNo(modelSJPackGoodsMXTab.SJSeqNo, nSJPackingTabID);
                    bSeqNoExist = true;
                   // modelSJPackGoodsMXTab.SJSeqNo = modelSJPackGoodsMXTab.SJSeqNo;
                }
                else
                {
                   // MessageBox.Show("序号不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                m_bllSJPackGoodsMXTab.TransAdd(modelSJPackGoodsMXTab, m_SQLStringList, m_arrayList);
                                
                int nPaidanRegisterTabID = 0;
                DataSet dsTemp = m_bllPaidanRegisterTab.GetAllPaiDanList("ContractCode = '" + this.comboBoxContractNo.Text + "'");
                if (dsTemp.Tables.Count > 0 && dsTemp.Tables[0].Rows.Count > 0)
                {
                    nPaidanRegisterTabID = Convert.ToInt32(dsTemp.Tables[0].Rows[0]["PaidanRegisterTabID"].ToString(), 10);
                }
                Decimal dtBackTaxPoint = 0;
                DataSet dsInfo = m_bllFactoryGoodsTab.GetGoodsBandInfo("PaidanRegisterTab.PaidanRegisterTabID = '"
                    + nPaidanRegisterTabID.ToString() + "'");
                if (dsInfo.Tables.Count > 0 && dsInfo.Tables[0].Rows.Count > 0)
                {
                    dtBackTaxPoint = Convert.ToDecimal(dsInfo.Tables[0].Rows[0]["退税点"].ToString());
                }

                Decimal dtFactorA = 0;
                dsInfo = m_bllFactoryDataTab.GetFactorAInfo("PaidanRegisterTab.PaidanRegisterTabID = '"
                    + nPaidanRegisterTabID.ToString() + "'");
                if (dsInfo.Tables.Count > 0 && dsInfo.Tables[0].Rows.Count > 0)
                {
                    dtFactorA = Convert.ToDecimal(dsInfo.Tables[0].Rows[0]["系数A"].ToString());
                }
                //增加相应的报关装箱单明细
                ds = m_bllBGPackingTab.GetList("BGSJPackDJNo = '" + n64NewDJNo + "'");

                DGBY.Model.BGPackGoodsMXTab modelBGPackGoodsMXTab = new DGBY.Model.BGPackGoodsMXTab();
                modelBGPackGoodsMXTab.GoodsMXName = modelSJPackGoodsMXTab.GoodsMXName;
                modelBGPackGoodsMXTab.GGXHZDEtc = modelSJPackGoodsMXTab.GGXHZDEtc;
                modelBGPackGoodsMXTab.GGXHZDEtc2 = modelSJPackGoodsMXTab.GGXHZDEtc2;
                modelBGPackGoodsMXTab.FPieceNum = modelSJPackGoodsMXTab.PieceNum;
                modelBGPackGoodsMXTab.FNumber = modelSJPackGoodsMXTab.Number;
                modelBGPackGoodsMXTab.FMaoWeight = modelSJPackGoodsMXTab.MaoWeight;
                modelBGPackGoodsMXTab.FFactWeight = modelSJPackGoodsMXTab.FactWeight;
                modelBGPackGoodsMXTab.CKHTDCost = modelSJPackGoodsMXTab.CKHTDCost;
                modelBGPackGoodsMXTab.CKHTJinE = modelSJPackGoodsMXTab.CKHTJinE;
                modelBGPackGoodsMXTab.BackTaxPoint = dtBackTaxPoint;
                modelBGPackGoodsMXTab.FactorA = dtFactorA;
                modelBGPackGoodsMXTab.BGPackingTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["BGPackingTabID"].ToString(), 10);
                if (bSeqNoExist)
                    m_bllBGPackGoodsMXTab.BGMoveRecordAfterSeqNo(modelSJPackGoodsMXTab.SJSeqNo, modelBGPackGoodsMXTab.BGPackingTabID);

                modelBGPackGoodsMXTab.BGSeqNo = modelSJPackGoodsMXTab.SJSeqNo;
                modelBGPackGoodsMXTab.NumDanWeiTabID = modelSJPackGoodsMXTab.NumDanWeiTabID;

                m_bllBGPackGoodsMXTab.TransAdd(modelBGPackGoodsMXTab, m_SQLStringList, m_arrayList, 0);
                m_bllSJPackingTab.ExecuteSqlTran(m_SQLStringList, m_arrayList);

                Frm_Main.Log2DB(this.Text, "增加明细", this.textBoxFirstSheetNo.Text);
                ShowAllMXRecordInDataGridView(modelSJPackGoodsMXTab.SJPackingTabID);
                //ClassUtility.ResetAllTextBoxInGroupBox(this.groupBoxGoodsDetail);
                return true;

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }

         private void ModifyGoodsDetail(int nRowIndex)
         {
             if (CheckSBDate())
             {
                 MessageBox.Show("综合登记表该合同号已经登记申报日期，不能修改单据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 return;
             }
             try
             {
                 m_SQLStringList.Clear();
                 m_arrayList.Clear();
                 UltraGridRow CurrentUGR;
                 CurrentUGR = ultraGrid2.Rows[nRowIndex];
                 m_nSelectSJPackGoodsMXTabID = Convert.ToInt32(CurrentUGR.Cells[0].Value.ToString(), 10);
                 DGBY.Model.SJPackGoodsMXTab modelSJPackGoodsMXTabOld = m_bllSJPackGoodsMXTab.GetModel(m_nSelectSJPackGoodsMXTabID);
                 if (modelSJPackGoodsMXTabOld == null)
                 {
                     MessageBox.Show("数据库不存在该记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     return;
                 }
            
                // DGBY.Model.SJPackGoodsMXTab modelSJPackGoodsMXTab = new DGBY.Model.SJPackGoodsMXTab();

                // modelSJPackGoodsMXTab.SJPackGoodsMXTabID = m_nSelectSJPackGoodsMXTabID;
                 modelSJPackGoodsMXTabOld.GoodsMXName = CurrentUGR.Cells["商品名称"].Value.ToString();
                 modelSJPackGoodsMXTabOld.GGXHZDEtc = CurrentUGR.Cells["质地"].Value.ToString();
                 modelSJPackGoodsMXTabOld.GGXHZDEtc2 = CurrentUGR.Cells["规格型号"].Value.ToString();
                 modelSJPackGoodsMXTabOld.PieceNum = Convert.ToInt32(CurrentUGR.Cells["件数"].Value.ToString(), 10);
                 //string st = CurrentUGR.Cells[7].ToString();
                 modelSJPackGoodsMXTabOld.Number = Convert.ToDecimal(CurrentUGR.Cells["数量"].Value.ToString());
                 modelSJPackGoodsMXTabOld.MaoWeight = Convert.ToDecimal(CurrentUGR.Cells["毛重"].Value.ToString());
                 modelSJPackGoodsMXTabOld.FactWeight = Convert.ToDecimal(CurrentUGR.Cells["净重"].Value.ToString());
                 modelSJPackGoodsMXTabOld.NumDanWeiTabID = Convert.ToInt32(CurrentUGR.Cells["单位"].Value.ToString(), 10);



                 modelSJPackGoodsMXTabOld.CKHTJinE = modelSJPackGoodsMXTabOld.CKHTDCost * modelSJPackGoodsMXTabOld.Number/*modelSJPackGoodsMXTabOld.CKHTJinE*/;
                 modelSJPackGoodsMXTabOld.GouHHTJinE = modelSJPackGoodsMXTabOld.GouHHTDCost * modelSJPackGoodsMXTabOld.Number;

                 m_bllSJPackGoodsMXTab.TransUpdate(modelSJPackGoodsMXTabOld, m_SQLStringList, m_arrayList);

                 DGBY.Model.SJPackingTab modelSJPackingTabOld = m_bllSJPackingTab.GetModel(modelSJPackGoodsMXTabOld.SJPackingTabID);

                 //更新报关装箱单
                 DataSet ds = m_bllBGPackingTab.GetList("BGSJPackDJNo = '" + modelSJPackingTabOld.SJPackDJNo.ToString() + "'");
                 if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                 {
                     int nBGPackingTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["BGPackingTabID"].ToString(), 10);

                     DataSet m_ds = m_bllBGPackGoodsMXTab.ShowGoodsMX("BGPackGoodsMXTab.BGSeqNo = '" + modelSJPackGoodsMXTabOld.SJSeqNo + "' and BGPackingTab.BGPackingTabID = '" + nBGPackingTabID + "'");
                     if (m_ds.Tables.Count > 0 && m_ds.Tables[0].Rows.Count > 0)
                     {
                         int nBGPackGoodsMXTabId = Convert.ToInt32(m_ds.Tables[0].Rows[0]["BGPackGoodsMXTabID"].ToString(), 10);
                         DGBY.Model.BGPackGoodsMXTab modelBGPackGoodsMXTab = m_bllBGPackGoodsMXTab.GetModel(nBGPackGoodsMXTabId);

                         modelBGPackGoodsMXTab.GoodsMXName = modelSJPackGoodsMXTabOld.GoodsMXName;
                         modelBGPackGoodsMXTab.GGXHZDEtc = modelSJPackGoodsMXTabOld.GGXHZDEtc;
                         modelBGPackGoodsMXTab.GGXHZDEtc2 = modelSJPackGoodsMXTabOld.GGXHZDEtc2;
                         modelBGPackGoodsMXTab.FPieceNum = modelSJPackGoodsMXTabOld.PieceNum;
                         modelBGPackGoodsMXTab.FNumber = modelSJPackGoodsMXTabOld.Number;
                         modelBGPackGoodsMXTab.FMaoWeight = modelSJPackGoodsMXTabOld.MaoWeight;
                         modelBGPackGoodsMXTab.FFactWeight = modelSJPackGoodsMXTabOld.FactWeight;
                         modelBGPackGoodsMXTab.CKHTDCost = modelSJPackGoodsMXTabOld.CKHTDCost;
                         modelBGPackGoodsMXTab.CKHTJinE = modelSJPackGoodsMXTabOld.CKHTJinE;
                         modelBGPackGoodsMXTab.HZMaoWeight = modelSJPackGoodsMXTabOld.GouHHTJinE;

                         modelBGPackGoodsMXTab.BGSeqNo = modelSJPackGoodsMXTabOld.SJSeqNo;
                         //modelBGPackGoodsMXTab.BackTaxPoint = modelSJPackGoodsMXTabOld.BackTaxPoint;

                         modelBGPackGoodsMXTab.NumDanWeiTabID = modelSJPackGoodsMXTabOld.NumDanWeiTabID;
                         m_bllBGPackGoodsMXTab.TransUpdate(modelBGPackGoodsMXTab, m_SQLStringList, m_arrayList);
                     }
                 }

                 m_bllSJPackingTab.ExecuteSqlTran(m_SQLStringList, m_arrayList);
                 Frm_Main.Log2DB(this.Text, "修改明细", modelSJPackingTabOld.SJPackDJNo.ToString());
                 ShowAllMXRecordInDataGridView(modelSJPackGoodsMXTabOld.SJPackingTabID);
               //  MessageBox.Show("数据修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
             catch (System.Exception ex)
             {
                 MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

             }
         }

        private void ultraGrid2_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
        {
            ClassUltraGridCommonSet.ultraGrid1_InitializeRowFilter(e);
            InitColumnWidth2();
            foreach (UltraGridColumn column2 in ultraGrid2.DisplayLayout.Bands[0].Columns)
            {
                string str = column2.Header.Caption;
                if (str == "金额" || str == "单价" || str == "币制" || str == "打折单价" || str == "打折金额")
                {
                    column2.CellAppearance.BackColor = Color.Gray;
                    column2.CellActivation = Activation.ActivateOnly;
                }
            }
            List<string> lstTemp = new List<string>();
            lstTemp.Add("件数");
            lstTemp.Add("数量");
            lstTemp.Add("毛重");
            lstTemp.Add("净重");
            lstTemp.Add("金额");

            //if (Frm_Main.m_bCompleteVer == true)
            //{
            //    lstTemp.Add("打折金额");
            //}

      
            ClassUltraGridCommonSet.SetSumColumn(e, lstTemp);
        }

        private void InitColumnWidth1()
        {
            ultraGrid1.DisplayLayout.Bands[0].Columns["单据编号"].Width = 90;
            ultraGrid1.DisplayLayout.Bands[0].Columns["合同编号"].Width = 75;
            ultraGrid1.DisplayLayout.Bands[0].Columns["经营单位"].Width = 160;
            ultraGrid1.DisplayLayout.Bands[0].Columns["收货单位"].Width = 130;
            ultraGrid1.DisplayLayout.Bands[0].Columns["起运国"].Width = 50;
            ultraGrid1.DisplayLayout.Bands[0].Columns["装运港"].Width = 50;
            ultraGrid1.DisplayLayout.Bands[0].Columns["包装种类"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["唛头"].Width = 70;
            ultraGrid1.DisplayLayout.Bands[0].Columns["是否为鞋的装箱单"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["牌子"].Width = 100;
            ultraGrid1.DisplayLayout.Bands[0].Columns["币制"].Width = 40;
            ultraGrid1.DisplayLayout.Bands[0].Columns["备注"].Width = 100;
        }

        private void InitColumnWidth2()
        {
            ultraGrid2.DisplayLayout.Bands[0].Columns["序号"].Width = 30;
            ultraGrid2.DisplayLayout.Bands[0].Columns["商品名称"].Width = 120;
            ultraGrid2.DisplayLayout.Bands[0].Columns["质地"].Width = 160;
            ultraGrid2.DisplayLayout.Bands[0].Columns["规格型号"].Width = 140;
            ultraGrid2.DisplayLayout.Bands[0].Columns["件数"].Width = 50;
            ultraGrid2.DisplayLayout.Bands[0].Columns["数量"].Width = 80;
            ultraGrid2.DisplayLayout.Bands[0].Columns["单位"].Width = 40;
            ultraGrid2.DisplayLayout.Bands[0].Columns["毛重"].Width = 80;
            ultraGrid2.DisplayLayout.Bands[0].Columns["净重"].Width = 80;
            ultraGrid2.DisplayLayout.Bands[0].Columns["币制"].Width = 40;
        }

        private void ultraGrid2_AfterCellActivate(object sender, EventArgs e)
        {
            m_nDelIndex = ultraGrid2.ActiveRow.Index;
        }

       

        private void button1_Click(object sender, EventArgs e)
        {
        }

        private void Frm_CommerCheckFillBoxSheet_VisibleChanged(object sender, EventArgs e)
        {
            //InitContractCombox();
        }

        private void Frm_CommerCheckFillBoxSheet_Move(object sender, EventArgs e)
        {

            try
            {
                Frm_Main.m_nContractSelectValue = (int)this.comboBoxContractNo.SelectedValue;
                InitContractNoCombox();
                m_bInsertFlag = false;
            }
            catch (System.Exception ex)
            {
              //  MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
         //   InitContractCombox();
        }

        private void Frm_CommerCheckFillBoxSheet_Activated(object sender, EventArgs e)
        {
            InitContractNoCombox();
            SyncContractNo();
            m_nDelIndex = -1;
        }

        private void InitContractNoCombox()
        {
            try
            {
                if (Frm_Main.m_nContractSelectValue == 127)
                    return;
                DataRow[] drs = m_dsPaidan.Tables[0].Select("PaidanRegisterTabID = '" + Frm_Main.m_nContractSelectValue.ToString() + "'");
                if (drs.Length > 0)
                    this.comboBoxContractNo.SelectedValue = Frm_Main.m_nContractSelectValue;
                else
                {
                    m_dsPaidan = m_bllPaidanRegisterTab.GetNameAndIDAll("");
                    if (m_dsPaidan.Tables.Count > 0 && m_dsPaidan.Tables[0].Rows.Count > 0)
                    {
                        this.comboBoxContractNo.DataSource = m_dsPaidan.Tables[0];
                        this.comboBoxContractNo.ValueMember = "PaidanRegisterTabID";
                        this.comboBoxContractNo.DisplayMember = "合同编号";
                        this.comboBoxContractNo.AutoCompleteSource = AutoCompleteSource.ListItems;
                        this.comboBoxContractNo.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                        this.comboBoxContractNo.SelectedValue = Frm_Main.m_nContractSelectValue;
                    }

                    this.comboBoxRecvGoodsComp.SelectedIndex = 0;
                              
                    this.comboBoxStartCountry.SelectedIndex = 0;
     
                    this.comboBoxPort.SelectedIndex = 0;
       
                    this.comboBoxOutSideCate.SelectedIndex = 0;
         
                    this.comboBoxCoinUnit2.SelectedIndex = 0;
                  
                }
            }
            catch (System.Exception ex)
            {
                //  MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }



        }
        private void Frm_CommerCheckFillBoxSheet_Deactivate(object sender, EventArgs e)
        {
            try
            {
                Frm_Main.m_nContractSelectValue = (int)this.comboBoxContractNo.SelectedValue;

            }
            catch (System.Exception ex)
            {
                //  MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        }

        private void ultraGrid2_Error(object sender, Infragistics.Win.UltraWinGrid.ErrorEventArgs e)
        {

        }


        private void ultraGrid2_AfterRowInsert(object sender, Infragistics.Win.UltraWinGrid.RowEventArgs e)
        {
            ultraGrid2.Rows[e.Row.Index].Cells[2].IgnoreRowColActivation = true;
            ultraGrid2.Rows[e.Row.Index].Cells[2].Activation = Activation.AllowEdit;
            ultraGrid2.Rows[e.Row.Index].Cells[2].Activate();
            ultraGrid2.PerformAction(UltraGridAction.EnterEditMode);
            m_bInsertFlag = true;
            InitNewAddRowValue(e.Row.Index);
        }
        //ultraGrid换行时触发
        private void ultraGrid2_BeforeRowUpdate(object sender, CancelableRowEventArgs e)
        {
            DataSet ds = m_bllSJPackingTab.ShowOneSJPackRec("SJPackingTab.SJPackDJNo = '" + this.textBoxFirstSheetNo.Text + "'");
            //int nSJPackingTabID = 0;
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {

            }
            else
            {
                MessageBox.Show("商检_装箱单概况表没有选中，所以无法修改货物明细!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
             
            try
            {
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid2.Rows[e.Row.Index];

                if (m_bInsertFlag)
                {
                    ultraGrid2.Rows[e.Row.Index].Cells[2].Activation = Activation.ActivateOnly;
                    m_bInsertFlag = false;
                    if(!AddGoodsDetail(e.Row.Index))
                        e.Cancel = true;
                        
                    
                   
                }
                else//修改
                {
             
                    ModifyGoodsDetail(e.Row.Index);
                    
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Cancel = true;
            }
        }

        private void ultraGrid2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter && e.Modifiers == Keys.Control)
            {
                if (CheckSBDate())
                {
                    MessageBox.Show("综合登记表该合同号已经登记申报日期，不能修改单据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                DataSet ds = m_bllSJPackingTab.ShowOneSJPackRec("SJPackingTab.SJPackDJNo = '" + this.textBoxFirstSheetNo.Text + "'");
                //int nSJPackingTabID = 0;
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {

                }
                else
                {
                    MessageBox.Show("商检_装箱单概况表没有选中，所以无法增加货物明细!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (!m_bInsertFlag)
                {

                    UltraGridRow row = this.ultraGrid2.DisplayLayout.Bands[0].AddNew();
                    //row.ParentCollection.Move(row, 0);
                    //this.ultraGrid2.ActiveRowScrollRegion.ScrollRowIntoView(row);
                }
            }
            switch (e.KeyCode)
            {
                case Keys.Up:
                    {
                        UltraGridCell gridCell = this.ultraGrid2.ActiveCell;
                        if (null == gridCell)
                            return;     

                        string strTemp = this.ultraGrid2.ActiveCell.Column.Header.Caption;
                        if (strTemp == "单位")
                            return;
                        int nColumnIndex = this.ultraGrid2.ActiveCell.Column.Index;
                        int nIndex = ultraGrid2.ActiveRow.Index;
                        if (nIndex > 0)
                            nIndex--;
                        this.ultraGrid2.PerformAction(UltraGridAction.ExitEditMode, false,
                          false);
                        this.ultraGrid2.PerformAction(UltraGridAction.AboveCell, false,
                          false);
                        e.Handled = true;
                        ultraGrid2.Rows[nIndex].Cells[nColumnIndex].IgnoreRowColActivation = true;
                        ultraGrid2.Rows[nIndex].Cells[nColumnIndex].Activation = Activation.AllowEdit;
                        ultraGrid2.Rows[nIndex].Cells[nColumnIndex].Activate();
                        this.ultraGrid2.PerformAction(UltraGridAction.EnterEditMode, false,
                          false);
                        break;
                    }

                case Keys.Down:
                    {
                        UltraGridCell gridCell = this.ultraGrid2.ActiveCell;
                        if (null == gridCell)
                            return;     

                        string strTemp = this.ultraGrid2.ActiveCell.Column.Header.Caption;
                        if (strTemp == "单位")
                            return;
                        int nColumnIndex = this.ultraGrid2.ActiveCell.Column.Index;
                        int nIndex = ultraGrid2.ActiveRow.Index;
                        if (nIndex < ultraGrid2.Rows.Count - 1)
                            nIndex++;
                        this.ultraGrid2.PerformAction(UltraGridAction.ExitEditMode, false,
                          false);
                        this.ultraGrid2.PerformAction(UltraGridAction.BelowCell, false,
                          false);
                        e.Handled = true;
                        ultraGrid2.Rows[nIndex].Cells[nColumnIndex].IgnoreRowColActivation = true;
                        ultraGrid2.Rows[nIndex].Cells[nColumnIndex].Activation = Activation.AllowEdit;
                        ultraGrid2.Rows[nIndex].Cells[nColumnIndex].Activate();
                        this.ultraGrid2.PerformAction(UltraGridAction.EnterEditMode, false,
                          false);
                        break;
                    }

                case Keys.Right:
                    this.ultraGrid2.PerformAction(UltraGridAction.ExitEditMode, false,
                      false);
                    this.ultraGrid2.PerformAction(UltraGridAction.NextCellByTab, false,
                      false);
                    e.Handled = true;
                    this.ultraGrid2.PerformAction(UltraGridAction.EnterEditMode, false,
                      false);
                    break;
                case Keys.Left:
                    this.ultraGrid2.PerformAction(UltraGridAction.ExitEditMode, false,
                      false);
                    this.ultraGrid2.PerformAction(UltraGridAction.PrevCellByTab, false,
                      false);
                    e.Handled = true;
                    this.ultraGrid2.PerformAction(UltraGridAction.EnterEditMode, false,
                      false);
                    break;
            }
        }

        private void ultraGrid2_BeforeRowCancelUpdate(object sender, CancelableRowEventArgs e)
        {
            m_bInsertFlag = false;
        }

        private void ultraGrid2_BeforeRowsDeleted(object sender, BeforeRowsDeletedEventArgs e)
        {
            e.DisplayPromptMsg = false;
            if (!m_bInsertFlag)
            {
                int nSelectSJPackGoodsMXTabID = Convert.ToInt32(ultraGrid2.ActiveRow.Cells[0].Value.ToString(), 10);
                DGBY.Model.SJPackGoodsMXTab modelSJPackGoodsMXTabOld = m_bllSJPackGoodsMXTab.GetModel(nSelectSJPackGoodsMXTabID);
                if (modelSJPackGoodsMXTabOld == null)
                {
                    MessageBox.Show("数据库不存在该记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (MessageBox.Show("确实要删除该条记录!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                {
                    try
                    {

                        m_bllSJPackGoodsMXTab.Delete(nSelectSJPackGoodsMXTabID);
                        DGBY.Model.SJPackingTab modelSJPackingTabOld = m_bllSJPackingTab.GetModel(modelSJPackGoodsMXTabOld.SJPackingTabID);

                        //更新报关装箱单
                        DataSet ds = m_bllBGPackingTab.GetList("BGSJPackDJNo = '" + modelSJPackingTabOld.SJPackDJNo.ToString() + "'");
                        int nBGPackingTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["BGPackingTabID"].ToString(), 10);
                        DataSet m_ds = m_bllBGPackGoodsMXTab.ShowGoodsMX("BGPackGoodsMXTab.BGSeqNo = '" + modelSJPackGoodsMXTabOld.SJSeqNo + "' and BGPackingTab.BGPackingTabID = '" + nBGPackingTabID + "'");
                        if (m_ds.Tables.Count > 0 && m_ds.Tables[0].Rows.Count > 0)
                        {
                            int nBGPackGoodsMXTabId = Convert.ToInt32(m_ds.Tables[0].Rows[0]["BGPackGoodsMXTabID"].ToString(), 10);
                            m_bllBGPackGoodsMXTab.Delete(nBGPackGoodsMXTabId);
                            Frm_Main.Log2DB(this.Text, "删除明细", modelSJPackingTabOld.SJPackDJNo.ToString());
                        }

                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        e.Cancel = true;
                    }
                }
                else
                {
                    e.Cancel = true;
                }
            }
            else
            {
                MessageBox.Show("插入未完成，不能删除记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Cancel = true;
            }
        }

        private void toolStripMenuItemDel_Click(object sender, EventArgs e)
        {
            if (CheckSBDate())
            {
                MessageBox.Show("综合登记表该合同号已经登记申报日期，不能修改单据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            int nIndex = m_nDelIndex;
            if(m_nDelIndex >= 0)
            {
                if (ultraGrid2.ActiveRow != null)
                {
                    ultraGrid2.ActiveRow.Delete(false);
                }
            }
            else
            {
                MessageBox.Show("请选中要删除的记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        
        
        private void button1_Click_1(object sender, EventArgs e)
        {
            this.textBoxInsertFlag.Text = m_bInsertFlag ? "true" : "false";

        }

        private void toolStripMenuItemAdd_Click(object sender, EventArgs e)
        {
            if (CheckSBDate())
            {
                MessageBox.Show("综合登记表该合同号已经登记申报日期，不能修改单据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            DataSet ds = m_bllSJPackingTab.ShowOneSJPackRec("SJPackingTab.SJPackDJNo = '" + this.textBoxFirstSheetNo.Text + "'");
            //int nSJPackingTabID = 0;
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {

            }
            else
            {
                MessageBox.Show("商检_装箱单概况表没有选中，所以无法增加货物明细!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (!m_bInsertFlag)
            {

                UltraGridRow row = this.ultraGrid2.DisplayLayout.Bands[0].AddNew();
                //row.ParentCollection.Move(row, 0);
                //this.ultraGrid2.ActiveRowScrollRegion.ScrollRowIntoView(row);
            }
        }

        private void ultraGrid2_AfterCellUpdate(object sender, CellEventArgs e)
        {
            if (e.Cell.Column.Key == "单位")
            {
                int nIndex = e.Cell.Row.Index;
                UltraGridRow CurrentUGR = ultraGrid2.Rows[nIndex];
                string strDanWei = e.Cell.Value.ToString();

                //  string strDanWei = CurrentUGR.Cells["单位"].Value.ToString();
                if (ClassInputValid.IsNum(strDanWei))
                {
                    DataSet ds = m_bllNumDanWeiTab.GetList(" NumDanWeiTabID= '" + strDanWei + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        strDanWei = ds.Tables[0].Rows[0]["单位名称"].ToString();
                        if (strDanWei == "千克")
                            CurrentUGR.Cells["净重"].Value = CurrentUGR.Cells["数量"].Value;
                    }
                }
                else
                {
                    if (strDanWei == "千克")
                        CurrentUGR.Cells["净重"].Value = CurrentUGR.Cells["数量"].Value;
                }
            }
            else if (e.Cell.Column.Key == "数量")
            {
                int nIndex = e.Cell.Row.Index;
                UltraGridRow CurrentUGR = ultraGrid2.Rows[nIndex];
                if (CurrentUGR.Cells["单位"].Value.ToString() == "千克" || CurrentUGR.Cells["单位"].Value.ToString() == "3")
                    CurrentUGR.Cells["净重"].Value = CurrentUGR.Cells["数量"].Value;
            }
        }

    }
}